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

Last change on this file since 21486 was 21486, checked in by LoisHaggard_NM, 8 weeks ago

NMBIS Backend QModules - idepi Scatterplot to allow blank beginning date and yield 14-day default period

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