1 | #NM_PctDesirableLow.def |
---|
2 | #Percentage .def file |
---|
3 | #Uses %spvar1% in place of name of variable and the var level for percentage |
---|
4 | # calculation [e.g., %spvar1%="bwtgp in (1 2)"] |
---|
5 | #spvar1 is set in Module.xml file as a configuration parameter value |
---|
6 | #Uses the IBIS-Q data_frame for cross1 and cross2 |
---|
7 | #NM_ version checks NM pop data for population size for cell suppression |
---|
8 | #NM_ version also calculate RSE and provides reliability_flag data |
---|
9 | # |
---|
10 | f type special |
---|
11 | #f data_where nmres=1 |
---|
12 | ######################################### |
---|
13 | --------BoNdArY-------- |
---|
14 | 1 script |
---|
15 | OPTIONS MPRINT MLOGIC SYMBOLGEN NONUMBER NODATE PAGESIZE=4000; |
---|
16 | OPTION SPOOL; |
---|
17 | |
---|
18 | ************************** 1. TMP ******************************; |
---|
19 | * The dataset 'tmp' is the numerator dataset with any filters ; |
---|
20 | * already applied (e.g., filtered to specific sex, age, year, ; |
---|
21 | * etc. population groups). The proc summary counts deaths ; |
---|
22 | * computes summary statistics by cross1 and cross2 on age. ; |
---|
23 | ****************************************************************; |
---|
24 | data tmp; set tmp; |
---|
25 | percentvar=0; |
---|
26 | if %spvar1% then percentvar=1; |
---|
27 | run; |
---|
28 | proc summary data=tmp; |
---|
29 | var percentvar; |
---|
30 | class %cross1% |
---|
31 | ?cross2? %cross2% |
---|
32 | ; |
---|
33 | output out=tmp sum=count n=totalnum; |
---|
34 | run; |
---|
35 | proc sort data=tmp; by %cross1% |
---|
36 | ?cross2? %cross2% |
---|
37 | ; run; |
---|
38 | proc print data=tmp noobs; |
---|
39 | title1 '---------------------------------'; |
---|
40 | title2 '1. TMP - numerator dataset'; |
---|
41 | run; |
---|
42 | |
---|
43 | *********************** 2. data_frame **************************; |
---|
44 | * df_%cross1%%cross2% is a dataset created by IBIS-Q. ; |
---|
45 | * It consists of %cross1% and %cross2% (if the user specified ; |
---|
46 | * %cross2%) and a variable named "count" that is set to "0". ; |
---|
47 | * The results of the proc summary must be merged with the ; |
---|
48 | * df_%cross1%%cross2% dataset. ; |
---|
49 | ****************************************************************; |
---|
50 | data frame; |
---|
51 | set df_%cross1%%cross2%; |
---|
52 | run; |
---|
53 | proc sort data=frame; by %cross1% |
---|
54 | ?cross2? %cross2% |
---|
55 | ; run; |
---|
56 | proc print data=frame noobs; |
---|
57 | title2 '2. Data Frame'; |
---|
58 | run; |
---|
59 | |
---|
60 | data new; |
---|
61 | merge frame tmp; *must list frame dataset first, then tmp; |
---|
62 | by %cross1% |
---|
63 | ?cross2? %cross2% |
---|
64 | ; |
---|
65 | run; |
---|
66 | proc print data=new noobs; |
---|
67 | title2 '2. NEW, after frame merged with tmp'; |
---|
68 | run; |
---|
69 | data tmp; |
---|
70 | set new; |
---|
71 | drop _TYPE_ _FREQ_; |
---|
72 | |
---|
73 | run; |
---|
74 | |
---|
75 | proc print data=tmp noobs; |
---|
76 | title2 '2. TMP'; |
---|
77 | run; |
---|
78 | |
---|
79 | *************** 3. Flag variable and popcross macro *************; |
---|
80 | * The flag variable checks the cross variables for presence of ; |
---|
81 | * variables that are found in the population dataset. IBIS-q ; |
---|
82 | * created popcross vars based on info from the .CFG file. ; |
---|
83 | * The popcross macro will merge the numerator and denominator ; |
---|
84 | * data, matching up the appropriate values of the cross vars. ; |
---|
85 | *****************************************************************; |
---|
86 | * IBIS does not need the population dataset to produce a percent.; |
---|
87 | * The following code, through the end of the macro, is used to ; |
---|
88 | * compute the RSE for the data stability indicator and to check ; |
---|
89 | * the numerator and denominator counts for the cell suppression. ; |
---|
90 | *****************************************************************; |
---|
91 | %let flag=0; |
---|
92 | ?popcross1? %let flag=1; |
---|
93 | ?popcross2? %let flag=1; |
---|
94 | ?popcross1? ?popcross2? %let flag=2; |
---|
95 | |
---|
96 | %macro popcross; |
---|
97 | |
---|
98 | %if &flag=0 %then %do; |
---|
99 | proc summary data=poptmp; |
---|
100 | var pop; |
---|
101 | output out=pop (drop=_TYPE_ _FREQ_) sum=pop; |
---|
102 | run; |
---|
103 | proc sql; |
---|
104 | create table rate as |
---|
105 | select tmp.*, pop.* |
---|
106 | from tmp, pop |
---|
107 | quit; |
---|
108 | %end; |
---|
109 | |
---|
110 | %if &flag=1 %then %do; |
---|
111 | proc summary data=poptmp; |
---|
112 | var pop; |
---|
113 | class %popcross1% %popcross2%; |
---|
114 | output out=pop (drop=_TYPE_ _FREQ_) sum=pop; |
---|
115 | run; |
---|
116 | data pop; |
---|
117 | set pop; |
---|
118 | rename |
---|
119 | ?popcross1? %popcross1%=%cross1% |
---|
120 | ?popcross2? %popcross2%=%cross2% |
---|
121 | ; |
---|
122 | run; |
---|
123 | proc sort data=pop; |
---|
124 | ?popcross1? by %cross1%; |
---|
125 | ?popcross2? by %cross2%; |
---|
126 | run; |
---|
127 | proc sort data=tmp; |
---|
128 | ?popcross1? by %cross1%; |
---|
129 | ?popcross2? by %cross2%; |
---|
130 | run; |
---|
131 | proc print data=pop noobs; title2 '3. POP - pop dataset'; run; |
---|
132 | data rate; |
---|
133 | merge tmp pop; |
---|
134 | ?popcross1? by %cross1%; |
---|
135 | ?popcross2? by %cross2%; |
---|
136 | run; |
---|
137 | %end; |
---|
138 | |
---|
139 | %if &flag=2 %then %do; |
---|
140 | proc summary data=poptmp; |
---|
141 | var pop; |
---|
142 | class %popcross1% %popcross2% ; |
---|
143 | output out=pop (drop=_TYPE_ _FREQ_) sum=pop; |
---|
144 | run; |
---|
145 | data pop; |
---|
146 | set pop; |
---|
147 | rename %popcross1%=%cross1% %popcross2%=%cross2% ; |
---|
148 | run; |
---|
149 | proc sort data=pop; |
---|
150 | by %cross1% %cross2%; |
---|
151 | run; |
---|
152 | proc sort data=tmp; |
---|
153 | by %cross1% %cross2%; |
---|
154 | run; |
---|
155 | data rate; |
---|
156 | merge tmp pop; |
---|
157 | by %cross1% %cross2% |
---|
158 | ; |
---|
159 | run; |
---|
160 | %end; |
---|
161 | %mend; |
---|
162 | %popcross; |
---|
163 | proc print data=rate; title2 'rate'; run; |
---|
164 | |
---|
165 | ********************** 4. tmp, again ****************************; |
---|
166 | * Create the output variables for the IBIS xml/map file. ; |
---|
167 | *****************************************************************; |
---|
168 | data tmp; |
---|
169 | set rate; |
---|
170 | if count>0 then do; |
---|
171 | rate=count/totalnum; |
---|
172 | rateper=(rate*100); |
---|
173 | stderr=sqrt(rate*(1-rate)/totalnum)*100; |
---|
174 | end; |
---|
175 | if count<=0 then do; |
---|
176 | rate=0; |
---|
177 | rateper=0; |
---|
178 | stderr=sqrt((3/totalnum)*(1-(3/totalnum))/totalnum)*100; |
---|
179 | end; |
---|
180 | t1=(rateper-(1.96*stderr)); |
---|
181 | if (t1<0) then t1=0; |
---|
182 | t2=(rateper+(1.96*stderr)); |
---|
183 | if (t2>100) then t2=100; |
---|
184 | LL=put(t1, 8.2); |
---|
185 | UL=put(t2, 8.2); |
---|
186 | LL=compress(LL); |
---|
187 | UL=compress(UL); |
---|
188 | n=count; |
---|
189 | if totalnum=. then totalnum=0; |
---|
190 | |
---|
191 | *********************** 5. Red Flag *****************************; |
---|
192 | * redflag is the statistical stability indicator based on the ; |
---|
193 | * relative standard error (RSE, or coefficient of variation). ; |
---|
194 | * Redflag values created here are converted to images or special ; |
---|
195 | * characters in IBIS-View application XSLTfiles, for instance: ; |
---|
196 | * (xslt\html\query\module\result\ResultPage.xslt, ...Values.xslt ; |
---|
197 | *****************************************************************; |
---|
198 | if count>0 then do; |
---|
199 | rse=(stderr/rateper); |
---|
200 | redflag=put('', $12.); |
---|
201 | if rse>.3 then redflag=put('Unstable', $12.); |
---|
202 | if rse>.5 then redflag=put('VeryUnstable', $12.); |
---|
203 | if stderr=. then redflag=put('Unstable', $12.); |
---|
204 | end; |
---|
205 | *no variance, n=0, rse=div by zero; |
---|
206 | if count<=0 then redflag=put('Unstable', $12.); |
---|
207 | *no value attribute for missing crossby values; |
---|
208 | if pop=. then redflag=put('', $12.); |
---|
209 | run; |
---|
210 | |
---|
211 | ************* 6. New Mexico Small Numbers Rule *********************; |
---|
212 | * Suppress cells if the numerator in (1 2 3) AND the denominator ; |
---|
213 | * is less than 20. For Counts, must run the crude rate code to ; |
---|
214 | * capture the denominator, but only output the N. ZWs program ; |
---|
215 | * uses ".A" to identify cells for suppression. I have co-opted ; |
---|
216 | * his method so I can use the NM logic for cell suppression instead ; |
---|
217 | * of the standard IBIS logic. And I need to use ZW's program ; |
---|
218 | * because it will suppress the table marginals that can be used to ; |
---|
219 | * calculate the suppressed cells. If this code is used, the .def ; |
---|
220 | * file should have the "NM_" prefix. Needs suppressed_variabes ; |
---|
221 | * code at the end of this file to work. ; |
---|
222 | ********************************************************************; |
---|
223 | data tmp; |
---|
224 | set tmp; |
---|
225 | if ((0<n<4) and (totalnum<5000)) then do; |
---|
226 | n = .A; |
---|
227 | rateper = .A; |
---|
228 | totalnum = .A; |
---|
229 | LL = put('**', 8.0); |
---|
230 | UL = put('**', 8.0); |
---|
231 | |
---|
232 | *Only one value attribute is allowed - so if suppressed, overwrite unstable; |
---|
233 | *This also puts ** in record code column for suppressed rows, and adds footnote; |
---|
234 | redflag = put('Suppressed', $12.); |
---|
235 | end; |
---|
236 | proc print data=tmp noobs; title2 '6. TMP - final dataset for IBIS View app'; |
---|
237 | run; |
---|
238 | |
---|
239 | --------BoNdArY-------- |
---|
240 | f out_variable rateper |
---|
241 | # definition for output file |
---|
242 | f xml_out_map_file XMLPctLow.map |
---|
243 | --------BoNdArY-------- |
---|
244 | f out_detail lbl_not_used__see_xml_out_map_file |
---|
245 | rateper 15.1 |
---|
246 | LL 15.3 |
---|
247 | UL 15.3 |
---|
248 | n 15.0 |
---|
249 | totalnum 15.0 |
---|
250 | redflag 15.0 |
---|
251 | --------BoNdArY-------- |
---|
252 | --------BoNdArY-------- |
---|
253 | 1 suppressed_variables 1 |
---|
254 | rateper |
---|
255 | --------BoNdArY-------- |
---|
256 | |
---|