source: main/adopters/nm/trunk/src/main/backend_qModules/3.0/_EPHT/childlead/CrudeRateNM_AnnZERO.def @ 19939

Last change on this file since 19939 was 19939, checked in by LoisHaggard_NM, 9 months ago

Creating subfolders for 2.3 and 3.0 qModules files

File size: 5.5 KB
Line 
1#f label Percentage&Crude&Rate&NM&ZERO
2f type special
3#########################################
4--------BoNdArY--------
51 script
6OPTIONS MPRINT MLOGIC SYMBOLGEN pagesize=4000;
7OPTION SPOOL;
8
9proc summary data=tmp;
10    var x;
11    class %cross1% %cross2%;
12    output out=tmp sum=number;
13proc print data=tmp; title1 ' '; title2 'TMP';
14run;
15
16/*the 'flag' variable is the number of crosstab
17  or grouping variables that are found in the
18  population dataset (from variable crosswalk
19  table in .CFG file). 
20  -popcross1 is the row crosstab variable
21  -popcross2 is the column crosstab variable     */ 
22 
23%let popflag=0;
24%let flag=0;
25%let pflag=0;
26?popcross1? %let flag=1;
27?popcross1? %let pflag=1;
28?popcross2? %let flag=1;
29?popcross2? %let pflag=2;
30
31?popcross1? ?popcross2? %let flag=2;
32
33%macro popcross;
34
35%if &flag=0 %then %do;
36  proc summary data=poptmp;
37    var popcount;
38    output out=pop sum=popnum;
39   run;
40  proc print data=pop;  title2 'POP';
41  run;
42  proc sql;
43    create table rate as
44    select tmp.*, pop.*
45    from tmp, pop
46  quit;
47%end;
48
49%if &flag=1 %then %do;
50        /*proc summary to sum across relevant population dataset records*/
51        proc summary data=poptmp;
52            var popcount;
53            class %popcross1% %popcross2%;
54            output out=pop sum=popnum;
55        proc print data=pop;  title2 'POP';
56        run;
57       
58        /*proc sql, full outer join to maintain records for all crossvar
59           values in the POPULATION dataset. This will create records in
60           the results table (e.g. for counties) with zero cases.  The
61           full join will also retain all records whether they have a
62           matching record or not - so the records with missing values
63           on a crossvar will also be included.*/
64        proc sql;
65            create table rate as
66            select tmp.*, pop.*,
67            coalesce
68            ?popcross1? (tmp.%cross1%, pop.%popcross1%)
69            ?popcross2? (tmp.%cross2%, pop.%popcross2%)
70            from pop full join tmp
71            on
72            ?popcross1? tmp.%cross1%=pop.%popcross1%;
73            ?popcross2? tmp.%cross2%=pop.%popcross2%; 
74        quit; 
75    data rate;
76     set rate;
77         %let popflag=1;
78    run;
79%end;
80
81%if &flag=2 %then %do;
82        proc summary data=poptmp;
83                var popcount;
84                class %popcross1% %popcross2%  ;
85                output out=pop sum=popnum;
86        proc print data=pop;  title2 'POP';
87        run;
88        /*proc sql, full outer join to maintain records for all crossvar
89           values in the POPULATION dataset. This will create records in
90           the results table (e.g. for counties) with zero cases.  The
91           full join will also retain all records whether they have a
92           matching record or not - so the records with missing values
93           on a crossvar will also be included.*/
94        proc sql;
95            create table rate as
96            select tmp.*, pop.*,
97            coalesce (tmp.%cross1%, pop.%popcross1%),
98            coalesce (tmp.%cross2%, pop.%popcross2%)
99            from pop full join tmp
100            on
101            tmp.%cross1%=pop.%popcross1% and
102            tmp.%cross2%=pop.%popcross2%; 
103        quit;
104    data  rate;
105      set rate;
106          %let popflag=2;
107    run;
108%end;
109
110%mend;
111
112%popcross;
113
114proc print data=rate; title2 'RATE';
115
116%macro criscros;
117       %if &popflag = 1 and &pflag = 1 %then %do;
118               %cross1% = _TEMA001;
119           %end;
120           %else
121       %if &popflag = 1 and &pflag = 2 %then %do;
122               %cross2% = _TEMA001;
123           %end;   
124%mend  criscros;
125
126%macro crostwo;
127       %if &popflag = 2 %then %do;
128               %cross1% = _TEMA001;
129               %cross2% = _TEMA002;
130           %end;
131%mend  crostwo;
132
133data tmp;
134  set rate;
135 
136      %criscros;
137          %crostwo;
138
139  if number=. then n=0; else n=number;
140  rate=n/popnum;
141  rateper=rate*100;
142  stderr=sqrt(rate*(1-rate)/popnum)*100;
143  if n=0 then stderr=sqrt((3/popnum)*(1-(3/popnum))/popnum)*100;
144  t1=(rateper-(1.96*stderr));
145  if (t1<0) then t1=0;
146  LL=put(t1, 8.2);
147  UL=put((rateper+(1.96*stderr)), 8.2);
148  LL=compress(LL);
149  UL=compress(UL);
150
151
152/*************************************************/
153/* Statictical Stability Indicator               */
154/* based on the relative standard error (RSE, or */
155/* coefficient of variance). Redflag values are  */
156/* converted to images or special characters in  */
157/* XSLT files (xslt\html\query\module\result\    */
158/* ResultPage.xslt and Values.xslt               */
159/*************************************************/
160
161  rse=(stderr/rateper);
162  if rse>.3 then redflag=1; *statistical stability – 1 red flag;
163  if rse>.5 then redflag=2; *statistical stability - 2 red flags;
164  if stderr=. then redflag=2; *no variance, n=1;
165keep %cross1% %cross2% n popnum rate rateper LL UL rse redflag;
166proc print data=tmp; title2 'TMP AGAIN';
167run;
168
169
170/**********************************************/
171/* New Mexico Small Numbers Rule              */
172/* For Count, just run the crude rate code but*/
173/* only output the N. That way, I can use the */
174/* popcount information to know whether to    */
175/* suppress the n.                            */
176/*********************************************
177
178data tmp;
179  set tmp;
180  if ((0<n<4) and (1<=popnum<5000)) then do;
181  n = .A;
182  rate = .A;
183end;
184*/
185proc print data=tmp; title2 'FINAL'; run;
186
187
188
189--------BoNdArY--------
190f out_variable rateper
191# definition for output file
192f xml_out_map_file XMLRateNumerDenomLCLUCL.map
193#################################################
194# definition for output file
195#f xml_out_map_file XMLCount.map
196--------BoNdArY--------
197f out_detail lbl_not_used__see_xml_out_map_file
198  rateper 15.3
199  n 15.0
200  popnum 15.0
201  LL 15.
202  UL 15.
203  redflag 15.0
204--------BoNdArY--------
205--------BoNdArY--------
2061 suppressed_variables 2
207n
208rateper
209--------BoNdArY--------
Note: See TracBrowser for help on using the repository browser.