source: main/adopters/nm/trunk/src/main/backend_qModules/3.0/idepi/NM_Scatterplot.def @ 21477

Last change on this file since 21477 was 21477, checked in by LoisHaggard_NM, 7 weeks ago

NMBIS Backend QModules - idepi Scatterplot

File size: 10.3 KB
Line 
1#NM_RateCrude1K_data_frame.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#f data_where nmres=1
10#########################################
11--------BoNdArY--------
121 script
13OPTIONS MPRINT MLOGIC SYMBOLGEN NONUMBER NODATE PAGESIZE=4000;
14OPTION SPOOL;
15
16%macro dates;
17        %if (%spvar2%=Yesterday) %then %do;
18         begdate=today()-14;
19         enddate=today()-1;
20        %end;
21        %else %do;
22          begdate=input ('%spvar1%', anydtdte32.);
23          enddate=input ('%spvar2%', anydtdte32.);
24          format begdate enddate mmddyy10.;
25        %end;
26        %mend;
27       
28        data tmp;
29                format begdate enddate invcreatedate mmddyy10.;
30                set tmp;
31                %dates;
32                if ((begdate<=invcreatedate) and (invcreatedate<=enddate)) ;
33                run;
34
35        proc print data=tmp (obs=20); var begdate invcreatedate enddate; run;
36
37 ************************** 1. TMP ******************************;
38 * The dataset 'tmp' is the numerator dataset that has been read ;
39 * in already by ibis-q. Any filters have already been applied.  ;
40 * The proc summary counts deaths by cross1 and cross2.          ;
41 * The variable "x" must be in the dataset, it is set equal to 1.;
42 ****************************************************************;
43        proc summary data=tmp;
44                where detention=2;
45                var x;
46                class %cross1%
47                ?cross2? %cross2%
48                ;
49                format count 15.0;
50                output out=tmp (drop=_TYPE_ _FREQ_) sum=count;
51        proc sort data=tmp out=sorted; by %cross1%
52                ?cross2? %cross2%
53                ; run;
54        proc print data=tmp ;
55                title1 '---------------------------------';
56                title2 '1. TMP - numerator dataset';
57                run;
58 
59 *********************** 2. data_frame **************************;
60 * df_%cross1%%cross2% is a dataset created by IBIS-Q.           ;
61 * It consists of %cross1% and %cross2% (if the user specified   ;
62 * %cross2%) and a variable named "count" that is set to "0".    ;
63 * The results of the proc summary must be merged with the       ;
64 * df_%cross1%%cross2% dataset.                                  ;
65 ****************************************************************;
66        data frame;
67                set df_%cross1%%cross2%;
68                run;
69        proc sort data=frame; by %cross1%
70                ?cross2? %cross2%
71                ; run;
72        proc print data=frame noobs;
73                title2 '2. Data Frame';
74                run;
75        data tmp;
76                merge frame sorted;   *list frame first, merge frame onto sorted;
77                by %cross1%
78                   ?cross2? %cross2%
79                ;
80                run;
81        proc print data=tmp noobs;
82                title2 '2. TMP';
83                run;
84
85 *************** 3. Flag variable and popcross macro *************;
86 * The flag variable checks the cross variables for presence of   ;
87 * variables that are found in the population dataset. IBIS-q     ;
88 * created popcross vars based on info from the .CFG file.        ;
89 * The popcross macro will merge the numerator and denominator    ;
90 * data, matching up the appropriate values of the cross vars.    ;
91 *****************************************************************;
92 * The Count measure does not need the population dataset. The    ;
93 * following code, through the end of the macro, is used to       ;
94 * compute the RSE for the data stability indicator and to check  ;
95 * the numerator and denominator  counts for the cell suppression.;
96 *****************************************************************;
97        %let flag=0;
98        ?popcross1? %let flag=1;
99        ?popcross2? %let flag=1;
100        ?popcross1? ?popcross2? %let flag=2;
101
102        %macro popcross;
103
104        %if &flag=0 %then %do;
105                proc summary data=poptmp;
106                        var popcount;
107                        output out=pop (drop=_TYPE_ _FREQ_) sum=popcount;
108                run;
109                proc sql;
110                        create table numbers as
111                        select tmp.*, pop.*
112                        from tmp, pop
113                quit;
114        %end;
115
116        %if &flag=1 %then %do;
117                proc summary data=poptmp;
118                        var popcount;
119                        class %popcross1% %popcross2%;
120                        output out=pop (drop=_TYPE_ _FREQ_) sum=popcount;
121                run;
122                proc sql;
123                        create table numbers as
124                        select tmp.*, pop.*
125                        from tmp left join pop
126                        on
127                        ?popcross1? tmp.%cross1%=pop.%popcross1%;
128                        ?popcross2? tmp.%cross2%=pop.%popcross2%; 
129                quit;
130        %end;
131
132        %if &flag=2 %then %do;
133                proc summary data=poptmp;
134                        var popcount;
135                        class %popcross1% %popcross2%  ;
136                        output out=pop (drop=_TYPE_ _FREQ_) sum=popcount;
137                run;
138                proc sql;
139                        create table numbers as
140                        select tmp.*, pop.*
141                        from tmp left join pop
142                        on
143                        tmp.%cross1%=pop.%popcross1% and
144                        tmp.%cross2%=pop.%popcross2%;
145                quit;
146        %end;
147        %mend;
148        %popcross;
149        proc print data=numbers noobs;  title2 '3. NUMBERS - tmp merged with pop dataset'; run;
150
151 ********************** 3.5. Test Positivity *********************;
152 * Create the output variables for the IBIS xml/map file.         ;
153 *****************************************************************;
154        data covid_tests;
155                set data.covid_tests;
156                %dates;
157
158        proc summary data=covid_tests;
159                where result in (2 3) and detention=2 and 1<=fipscnty<=61
160                        and (_DT_LAB_ADDED>=begdate and _DT_LAB_ADDED<=enddate and _SPECIMEN_COLL_DT>=_DT_LAB_ADDED-14);
161                var x;
162                class fipscnty;
163                output out=negatives (drop= _TYPE_ _FREQ_) sum(x)=countneg;
164                run;
165        data numbers2;
166                merge negatives numbers;   *frame first, merge frame onto sorted;
167                by fipscnty;
168                run;
169        proc print data=numbers2 noobs;
170                title2 '2. TMP';
171                run;
172
173 ********************** 4. tmp, again ****************************;
174 * Create the output variables for the IBIS xml/map file.         ;
175 *****************************************************************;
176        data tmp;
177                set numbers2;
178                if  1<=fipscnty<=61 ;
179                testdenom=count+countneg;
180                if testdenom>0 then do;
181                        positivity=count/testdenom*100;
182                end;
183                else positivity=0;
184                rate=count/14/popcount;
185                rateper=(rate*100000);
186                if count>0 then do;
187                                stderr=sqrt(rate*(1-rate)/14/popcount)*100000;
188                        end;
189                if count=0 then do;
190                                stderr=sqrt((3/14/popcount)*(1-(3/popcount))/14/popcount)*100000;
191                        end;
192                t1=(rateper-(1.96*stderr));
193                if (t1<0) then t1=0;
194                LL=put(t1, 8.2);
195                UL=put((rateper+(1.96*stderr)), 8.2);
196                LL=compress(LL);
197                UL=compress(UL);
198                n=count;        *ibis-q needs a count variable named 'n';
199                format rank 1.0;
200                if rateper<8 and positivity<5 then rank=1;
201                if rateper<8 and positivity>=5 then rank=2;
202                if rateper>=8 and positivity<5 then rank=3;
203                if rateper>=8 and positivity>=5 then rank=4;
204
205 *********************** 5. Red Flag *****************************;
206 * redflag is the statistical stability indicator based on the    ;
207 * relative standard error (RSE, or coefficient of variation).    ;
208 * Redflag values created here are converted to images or special ;
209 * characters in IBIS-View application XSLTfiles, for instance:   ;
210 * (xslt\html\query\module\result\ResultPage.xslt, ...Values.xslt ;
211 *****************************************************************;
212                if count>0 then do;
213                        rse=(stderr/rateper);
214                        redflag=put('', $12.);
215                        if rse>.3 then redflag=put('Unstable', $12.);
216                        if rse>.5 then redflag=put('VeryUnstable', $12.);
217                        if stderr=. then redflag=put('Unstable', $12.);
218                end;
219                *no variance, n=0, rse=div by zero;
220                if count<=0 then redflag=put('Unstable', $12.);
221        run;
222       
223        proc summary data=tmp nway;
224                class rank;
225                output out=whichranks (drop= _TYPE_ _FREQ_) sum(count)=;
226                run;
227                proc print data=whichranks noobs; title 'whichranks'; run;
228        data fourranks;
229                do
230                        fourrank=1 to 4 by 1;
231                        output;
232                end;
233        proc print data=fourranks; title 'fourranks'; run;
234        proc sql;
235                create table getranks as
236                select fourranks.*, whichranks.*
237                from fourranks left join whichranks
238                on fourranks.fourrank=whichranks.rank;
239                quit;
240        proc print data=getranks noobs; title 'getranks'; run;
241        data addranks;
242                set getranks;
243                %cross1%=fourrank+80;
244                if fourrank=rank then delete;
245                rank=fourrank;
246                drop fourrank;
247                run;
248        proc print data=addranks noobs; title 'addranks'; run;
249
250
251 ************* 6. New Mexico Small Numbers Rule ********************;
252 * Suppress cells if the numerator in (1 2 3) AND the denominator   ;
253 * is less than 20. For Counts, must run the crude rate code to     ;
254 * capture the denominator, but only output the N. ZW’s program     ;
255 * uses ".A" to identify cells for suppression. I have co-opted     ;
256 * his method so I can use the NM logic for cell suppression instead;
257 * of the standard IBIS logic. And I need to use ZW's program       ;
258 * because it will suppress the table marginals that can be used to ;
259 * calculate the suppressed cells. If this code is used, the .def   ;
260 * file should have the "NM_" prefix. Needs suppressed_variabes     ;
261 * code at the end of this file to work.                            ;
262 *******************************************************************;
263        data tmp;
264                set tmp addranks;
265/*              if popcount=. and (0<=n<4) then delete; *if unknown row is only suppressed row;
266                else if ((0<n<4) and (.<popcount<20)) then do;
267                        rateper = .A;
268                        n = .A;
269                        popcount = .A;
270                        LL = put('**', 8.0);
271                        UL = put('**', 8.0);
272
273                *Only one value attribute is allowed - so if suppressed, overwrite unstable;
274                *This also puts ** in record code column for suppressed rows, and adds footnote;
275                        redflag = put('Suppressed', $12.);
276                end;
277*/
278                if popcount=. then redflag=put('', $12.); *no value attribute for missing crossby values;
279                if upcase(%cross1%) = FIPSCNTY then do; if fipscnty=97 then delete; end;
280        run;
281        proc print data=tmp noobs;  title2 '4. TMP - final dataset to pass to IBIS View app';
282        run;
283
284--------BoNdArY--------
285# definition for output file
286f out_variable rateper
287f xml_out_map_file XMLScatterplot.map
288--------BoNdArY--------
289f out_detail lbl_not_used__see_xml_out_map_file
290  rank 15.0
291  count 15.0
292  testdenom 15.0
293  positivity 15.1
294  rateper 15.1
295--------BoNdArY--------
296#**************** 7. suppressed variables **************************;
297# ZW’s CGI program must be told how many variables it will need to  ;
298# suppress and which ones they are. NOTE: If the SAS code, above, is;
299# commented out, these lines can be left in the .def file without   ;
300# causing any problems. They will only be used if the SAS code,     ;
301# above is active, OR if the small_num and small_pop parameters     ;
302# are active in the .CFG file, and with non-zero values.            ;
303#*******************************************************************;
304--------BoNdArY--------
3051 suppressed_variables 0
306--------BoNdArY--------
Note: See TracBrowser for help on using the repository browser.