source: main/adopters/nj/trunk/src/main/ibisq/qModules3/hiv/RateCrude100K.def @ 26872

Last change on this file since 26872 was 26872, checked in by Maria Baron, 3 months ago

hiv v3 query now works

File size: 8.0 KB
Line 
1#RateCrude100K.def
2#Calculates crude rates for records that have been filtered by IBIS-Q (data=tmp)
3#Uses the IBIS-Q data_frame for cross1 and cross2
4#NM_ = New Mexico cell suppression version
5#Applies NM cell suppression rules
6#Outputs redflag var based on RSE
7#
8f type special
9#########################################
10--------BoNdArY--------
111 script
12OPTIONS MPRINT MLOGIC SYMBOLGEN NONUMBER NODATE PAGESIZE=4000;
13OPTION SPOOL;
14
15 ************************** 1. TMP ******************************;
16 * The dataset 'tmp' is the numerator dataset that has been read ;
17 * in already by ibis-q. Any filters have already been applied.  ;
18 * The proc summary counts deaths by cross1 and cross2.          ;
19 ****************************************************************;
20        proc summary data=tmp;
21                var x;
22                class %cross1%
23                ?cross2? %cross2%
24                ;
25                output out=tmp (drop=_TYPE_ _FREQ_) sum=count;
26        proc sort data=tmp out=sorted; by %cross1%
27                ?cross2? %cross2%
28                ; run;
29        proc print data=sorted noobs;
30                title1 '---------------------------------';
31                title2 '1. TMP - numerator dataset';
32                run;
33 
34 *********************** 2. data_frame **************************;
35 * df_%cross1%%cross2% is a dataset created by IBIS-Q.           ;
36 * It consists of %cross1% and %cross2% (if the user specified   ;
37 * %cross2%) and a variable named "count" that is set to "0".    ;
38 * The results of the proc summary must be merged with the       ;
39 * df_%cross1%%cross2% dataset.                                  ;
40 * We don't use the cross1 and cross2 subtotals, anymore, we     ;
41 * only use the grand total in the but Kendo table result, but   ;
42 * don't delete them because it will mess up the table marginal  ;
43 * cell suppression - it will suppress table rows in the table   ;
44 * body when it doesn't find the cross1 and cross2 totals.       ;
45 ****************************************************************;
46        data frame;
47                set df_%cross1%%cross2%;
48                run;
49        proc sort data=frame; by %cross1%
50                ?cross2? %cross2%
51                ; run;
52        proc print data=frame noobs;
53                title2 '2. Data Frame';
54                run;
55
56        *set length so that values don't get truncated;
57        *listing frame dataset first will retain all records in frame;
58        data tmp;
59                length count 8;
60                merge frame sorted;
61                by %cross1%
62                   ?cross2? %cross2%
63                ;
64                run;
65        proc print data=tmp noobs;
66                title2 '2. tmp, after merged with frame';
67                run;
68
69 *************** 3. Flag variable and popcross macro *************;
70 * The flag variable checks the cross variables for presence of   ;
71 * variables that are found in the population dataset. IBIS-q     ;
72 * created popcross vars based on info from the .CFG file.        ;
73 * The popcross macro will merge the numerator and denominator    ;
74 * data, matching up the appropriate values of the cross vars.    ;
75 *****************************************************************;
76        %let flag=0;
77        ?popcross1? %let flag=1;
78        ?popcross2? %let flag=1;
79        ?popcross1? ?popcross2? %let flag=2;
80
81        %macro popcross;
82
83        %if &flag=0 %then %do;
84                proc summary data=poptmp;
85                        var popcount;
86                        output out=pop (drop=_TYPE_ _FREQ_) sum=popcount;
87                run;
88                proc sql;
89                        create table numbers as
90                        select tmp.*, pop.*
91                        from tmp, pop
92                quit;
93        %end;
94
95        %if &flag=1 %then %do;
96                proc summary data=poptmp;
97                        var popcount;
98                        class %popcross1% %popcross2%;
99                        output out=pop (drop=_TYPE_ _FREQ_) sum=popcount;
100                run;
101                proc sql;
102                        create table numbers as
103                        select tmp.*, pop.*
104                        from tmp left join pop
105                        on
106                        ?popcross1? tmp.%cross1%=pop.%popcross1%;
107                        ?popcross2? tmp.%cross2%=pop.%popcross2%; 
108          quit;
109        %end;
110
111        %if &flag=2 %then %do;
112                proc summary data=poptmp;
113                        var popcount;
114                        class %popcross1% %popcross2%  ;
115                        output out=pop (drop=_TYPE_ _FREQ_) sum=popcount;
116                run;
117                proc sql;
118                        create table numbers as
119                        select tmp.*, pop.*
120                        from tmp left join pop
121                        on
122                        tmp.%cross1%=pop.%popcross1% and
123                        tmp.%cross2%=pop.%popcross2%;
124                quit;
125        %end;
126        %mend;
127        %popcross;
128
129        proc print data=numbers noobs;
130                title2 '3. numbers, after pop merged with tmp';
131                run;
132
133 ********************** 4. tmp, again ****************************;
134 * Create the output variables for the IBIS xml/map file.         ;
135 *****************************************************************;
136        data rate;
137                set numbers;
138                        if count>0 then do;
139                                rate=count/popcount;
140                                rateper=(rate*100000);
141                        end;
142                        if count<=0 then do;
143                                rate=3/popcount;
144                                rateper=0;
145                        end;
146                stderr=sqrt(rate*(1-rate)/popcount)*100000;
147                t1=(rateper-(1.96*stderr));
148                if (t1<0) then t1=0;
149                LL=put(t1, 8.2);
150                UL=put((rateper+(1.96*stderr)), 8.2);
151                LL=compress(LL);
152                UL=compress(UL);
153                n=count;        *ibis-q needs a count variable named 'n';
154
155 *********************** 5. Red Flag *****************************;
156 * redflag is the statistical stability indicator based on the    ;
157 * relative standard error (RSE, or coefficient of variation).    ;
158 * Redflag values created here are converted to images or special ;
159 * characters in IBIS-View application XSLTfiles, for instance:   ;
160 * (xslt\html\query\module\result\ResultPage.xslt, ...Values.xslt ;
161 *****************************************************************;
162/*              if count>0 then do;
163                        rse=(stderr/rateper);
164                        redflag=put('', $12.);
165                        if rse>.3 then redflag=put('Unstable', $12.);
166                        if rse>.5 then redflag=put('VeryUnstable', $12.);
167                        if stderr=. then redflag=put('Unstable', $12.);
168                end;
169                if count<=0 then redflag=put('Unstable', $12.);   *no variance, n=0, rse=div by zero;
170        run;
171        proc print data=rate noobs;
172                title2 '2. rate, rate rateper stderr UCL LL calculated';
173                run;
174*/
175 ************* 6. New Mexico Small Numbers Rule ********************;
176 * Suppress cells if the numerator in (1 2 3) AND the denominator   ;
177 * is less than 20. For Counts, must run the crude rate code to     ;
178 * capture the denominator, but only output the N. ZW’s program     ;
179 * uses ".A" to identify cells for suppression. I have co-opted     ;
180 * his method so I can use the NM logic for cell suppression instead;
181 * of the standard IBIS logic. And I need to use ZW's program       ;
182 * because it will suppress the table marginals that can be used to ;
183 * calculate the suppressed cells. If this code is used, the .def   ;
184 * file should have the "NM_" prefix. Needs suppressed_variabes     ;
185 * code at the end of this file to work.                            ;
186 *******************************************************************;
187        data tmp;
188                set rate;
189                if  popcount ne . and 0<n<20 then do;
190                        rateper = .A;
191                        n = .A;
192                        popcount = .A;
193                        *LL = .A;
194                        *UL = .A;
195                        LL = put('**', 8.0);
196                        UL = put('**', 8.0);
197
198                *Only one value attribute is allowed - so if suppressed, overwrite unstable;
199                *This also puts ** in record code column for suppressed rows, and adds footnote;
200                        redflag = put('Suppressed', $12.);
201                end;
202                *if pop=. then redflag=put('', $12.); *no value attribute for missing crossby values;
203        proc print data=tmp noobs;  title2 '6. TMP - final dataset to pass to IBIS View app';
204        run;
205
206--------BoNdArY--------
207# definition for output file
208f out_variable rateper
209f xml_out_map_file XMLRate100KLow.map
210--------BoNdArY--------
211f out_detail lbl_not_used__see_xml_out_map_file
212  rateper 15.1
213  LL 15.3
214  UL 15.3
215  n 15.0
216  popcount 15.0
217  redflag 12.0
218--------BoNdArY--------
219 
220 ****************** 7. SUPPRESSED VARIABLES *************************;
221 * ZW's CGI program must be told how many variables it will need to  ;
222 * suppress and which ones they are. NOTE: If the SAS code, above, is;
223 * commented out, these lines can be left in the .def file without   ;
224 * causing any problems. They will only be used if the SAS code,     ;
225 * above is active, OR if the small_num and small_pop parameters     ;
226 * are active in the .CFG file, and with non-zero values.            ;
227 ********************************************************************;
228--------BoNdArY--------
2291 suppressed_variables 5
230  rateper
231  LL
232  UL
233  n
234  pop
235--------BoNdArY--------
Note: See TracBrowser for help on using the repository browser.