1 | #f label Percentage&Crude&Rate&NM&ZERO |
---|
2 | f type special |
---|
3 | ######################################### |
---|
4 | --------BoNdArY-------- |
---|
5 | 1 script |
---|
6 | OPTIONS MPRINT MLOGIC SYMBOLGEN pagesize=4000; |
---|
7 | OPTION SPOOL; |
---|
8 | |
---|
9 | proc summary data=tmp; |
---|
10 | var x; |
---|
11 | class %cross1% %cross2%; |
---|
12 | output out=tmp sum=number; |
---|
13 | proc print data=tmp; title1 ' '; title2 'TMP'; |
---|
14 | run; |
---|
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 | |
---|
114 | proc 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 | |
---|
133 | data tmp; |
---|
134 | set rate; |
---|
135 | |
---|
136 | %criscros; |
---|
137 | %crostwo; |
---|
138 | |
---|
139 | if number=. then n=0; else n=number; |
---|
140 | rate=n/popnum; |
---|
141 | PctPersons=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=(PctPersons-(1.96*stderr)); |
---|
145 | if (t1<0) then t1=0; |
---|
146 | LL=put(t1, 8.2); |
---|
147 | UL=put((PctPersons+(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 | if n>0 then do; |
---|
162 | rse=(stderr/PctPersons); |
---|
163 | redflag=put('', $12.); |
---|
164 | if rse>.3 then redflag=put('Unstable', $12.); |
---|
165 | if rse>.5 then redflag=put('VeryUnstable', $12.); |
---|
166 | if stderr=. then redflag=put('Unstable', $12.); |
---|
167 | end; |
---|
168 | if n<=0 then redflag=put('Unstable', $12.); |
---|
169 | |
---|
170 | keep %cross1% %cross2% n popnum rate PctPersons LL UL rse redflag; |
---|
171 | proc print data=tmp; title2 'TMP AGAIN'; |
---|
172 | run; |
---|
173 | |
---|
174 | |
---|
175 | /**********************************************/ |
---|
176 | /* New Mexico Small Numbers Rule */ |
---|
177 | /* For Count, just run the crude rate code but*/ |
---|
178 | /* only output the N. That way, I can use the */ |
---|
179 | /* popcount information to know whether to */ |
---|
180 | /* suppress the n. */ |
---|
181 | /********************************************* |
---|
182 | |
---|
183 | |
---|
184 | data tmp; |
---|
185 | set tmp; |
---|
186 | if ((0<n<4) and (.<popcount<5000)) then do; |
---|
187 | rateper = .A; |
---|
188 | n = .A; |
---|
189 | popcount = .A; |
---|
190 | LL = put('**', 8.0); |
---|
191 | UL = put('**', 8.0); |
---|
192 | redflag = put('Suppressed', $12.); |
---|
193 | end; |
---|
194 | if popcount=. then redflag=put('', $12.); |
---|
195 | |
---|
196 | |
---|
197 | */ |
---|
198 | proc print data=tmp; title2 'FINAL'; run; |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | --------BoNdArY-------- |
---|
203 | f out_variable PctPersons |
---|
204 | # definition for output file |
---|
205 | f xml_out_map_file XMLRateNumerDenomLCLUCL.map |
---|
206 | ################################################# |
---|
207 | # definition for output file |
---|
208 | #f xml_out_map_file XMLCount.map |
---|
209 | --------BoNdArY-------- |
---|
210 | f out_detail lbl_not_used__see_xml_out_map_file |
---|
211 | PctPersons 15.3 |
---|
212 | n 15.0 |
---|
213 | popnum 15.0 |
---|
214 | LL 15. |
---|
215 | UL 15. |
---|
216 | redflag 15.0 |
---|
217 | --------BoNdArY-------- |
---|
218 | --------BoNdArY-------- |
---|
219 | 1 suppressed_variables 2 |
---|
220 | n |
---|
221 | PctPersons |
---|
222 | --------BoNdArY-------- |
---|