1 | #S_RateCrude100K_YPLL_5YrAvg.def |
---|
2 | #Calculates YPLL rate from age 75 per 100,000 at time of death for |
---|
3 | # 5-year moving averages for records in data=tmp (records |
---|
4 | # that have been filtered by user) |
---|
5 | #Uses the IBIS-Q data_frame for cross1 |
---|
6 | #S_ = New Mexico cell suppression version |
---|
7 | #Applies NM cell suppression rules |
---|
8 | #Outputs redflag var based on RSE |
---|
9 | # |
---|
10 | f type special |
---|
11 | ######################################### |
---|
12 | --------BoNdArY-------- |
---|
13 | 1 script |
---|
14 | OPTIONS MPRINT MLOGIC SYMBOLGEN NONUMBER NODATE PAGESIZE=4000; |
---|
15 | OPTION SPOOL; |
---|
16 | |
---|
17 | ************************** 1. TMP ******************************; |
---|
18 | * The dataset 'tmp' is the numerator dataset that has been read ; |
---|
19 | * in already by ibis-q. Any filters have already been applied. ; |
---|
20 | * The proc summary counts deaths by cross1 and cross2. ; |
---|
21 | * The variable "x" must be in the dataset, it is set equal to 1.; |
---|
22 | * spvar1 is the first year that data are available for the ; |
---|
23 | * dataset. The spvar1 value is set in the Module.xml file. ; |
---|
24 | ****************************************************************; |
---|
25 | %let begyear=%spvar1%; *set beg year for year groups; |
---|
26 | |
---|
27 | ****************************************************************************; |
---|
28 | * Start by calculating the YPLL for each individual death. ; |
---|
29 | ****************************************************************************; |
---|
30 | data tmp; |
---|
31 | set tmp; |
---|
32 | years=0; |
---|
33 | if age<75 then do; |
---|
34 | years=(75-age); |
---|
35 | end; |
---|
36 | run; |
---|
37 | |
---|
38 | ****************************************************************************; |
---|
39 | * Then get death counts by cross variable(s). ; |
---|
40 | ****************************************************************************; |
---|
41 | proc summary data=tmp; |
---|
42 | var years; |
---|
43 | class %cross1% |
---|
44 | ?cross2? %cross2% |
---|
45 | ; |
---|
46 | output out=tmp (drop=_TYPE_ _FREQ_) sum=count; |
---|
47 | run; |
---|
48 | proc sort data=tmp out=sorted; by %cross1% |
---|
49 | ?cross2? %cross2% |
---|
50 | ; run; |
---|
51 | proc print data=tmp noobs; |
---|
52 | title1 '---------------------------------'; |
---|
53 | title2 '1. TMP - numerator dataset'; |
---|
54 | run; |
---|
55 | |
---|
56 | *********************** 2. data_frame **************************; |
---|
57 | * df_%cross1%%cross2% is a dataset created by IBIS-Q. ; |
---|
58 | * It consists of %cross1% and %cross2% (if the user specified ; |
---|
59 | * %cross2%) and a variable named "count" that is set to "0". ; |
---|
60 | * The results of the proc summary must be merged with the ; |
---|
61 | * df_%cross1%%cross2% dataset. ; |
---|
62 | ****************************************************************; |
---|
63 | data frame; |
---|
64 | set df_%cross1%%cross2%; |
---|
65 | run; |
---|
66 | proc sort data=frame; by %cross1% |
---|
67 | ?cross2? %cross2% |
---|
68 | ; run; |
---|
69 | title2 '2. Data Frame'; |
---|
70 | proc contents data=frame; run; |
---|
71 | proc print data=frame noobs; run; |
---|
72 | |
---|
73 | data tmp; |
---|
74 | merge frame sorted; *must list frame dataset first, then tmp; |
---|
75 | by %cross1% |
---|
76 | ?cross2? %cross2% |
---|
77 | ; |
---|
78 | run; |
---|
79 | proc print data=tmp noobs; |
---|
80 | title2 '2. TMP'; |
---|
81 | run; |
---|
82 | |
---|
83 | *************** 3. Flag variable and popcross macro *************; |
---|
84 | * The flag variable checks the cross variables for presence of ; |
---|
85 | * variables that are found in the population dataset. IBIS-q ; |
---|
86 | * created popcross vars based on info from the .CFG file. ; |
---|
87 | * The popcross macro will merge the numerator and denominator ; |
---|
88 | * data, matching up the appropriate values of the cross vars. ; |
---|
89 | *****************************************************************; |
---|
90 | %let flag=0; |
---|
91 | ?popcross1? %let flag=1; |
---|
92 | ?popcross2? %let flag=1; |
---|
93 | ?popcross1? ?popcross2? %let flag=2; |
---|
94 | |
---|
95 | %macro popcross; |
---|
96 | |
---|
97 | %if &flag=0 %then %do; |
---|
98 | proc summary data=poptmp ; |
---|
99 | var popcount; |
---|
100 | output out=pop (drop=_TYPE_ _FREQ_) sum=popcount; |
---|
101 | run; |
---|
102 | proc sql; |
---|
103 | create table numbers as |
---|
104 | select tmp.*, pop.* |
---|
105 | from tmp, pop |
---|
106 | quit; |
---|
107 | %end; |
---|
108 | |
---|
109 | %if &flag=1 %then %do; |
---|
110 | proc summary data=poptmp ; |
---|
111 | var popcount; |
---|
112 | class %popcross1% %popcross2%; |
---|
113 | output out=pop (drop=_TYPE_ _FREQ_) sum=popcount; |
---|
114 | run; |
---|
115 | proc sql; |
---|
116 | create table numbers as |
---|
117 | select tmp.*, pop.* |
---|
118 | from tmp, pop |
---|
119 | where |
---|
120 | ?popcross1? tmp.%cross1%=pop.%popcross1%; |
---|
121 | ?popcross2? tmp.%cross2%=pop.%popcross2%; |
---|
122 | quit; |
---|
123 | %end; |
---|
124 | |
---|
125 | %if &flag=2 %then %do; |
---|
126 | proc summary data=poptmp ; |
---|
127 | var popcount; |
---|
128 | class %popcross1% %popcross2% ; |
---|
129 | output out=pop (drop=_TYPE_ _FREQ_) sum=popcount; |
---|
130 | run; |
---|
131 | proc sql; |
---|
132 | create table numbers as |
---|
133 | select tmp.*, pop.* |
---|
134 | from tmp, pop |
---|
135 | where tmp.%cross1%=pop.%popcross1% and |
---|
136 | tmp.%cross2%=pop.%popcross2%; |
---|
137 | quit; |
---|
138 | %end; |
---|
139 | %mend; |
---|
140 | %popcross; |
---|
141 | ?cross2? proc sort data=numbers; |
---|
142 | ?cross2? by %cross2%; |
---|
143 | ?cross2? run; |
---|
144 | proc print data=numbers noobs; |
---|
145 | title2 '3. NUMBERS dataset'; |
---|
146 | run; |
---|
147 | |
---|
148 | ******** 4. Use lag function to sum across multiple rows ********; |
---|
149 | * Read the numbers dataset by the cross2 variable and then use ; |
---|
150 | * the lag function to sum across multiple rows. ; |
---|
151 | *****************************************************************; |
---|
152 | data numbers; |
---|
153 | set numbers; |
---|
154 | ?cross2? by %cross2%; |
---|
155 | count5= sum(count, lag(count), lag2(count), lag3(count), lag4(count)); |
---|
156 | popcount5= sum(popcount, lag(popcount), lag2(popcount), lag3(popcount), lag4(popcount)); |
---|
157 | drop _TYPE_ _FREQ_; |
---|
158 | run; |
---|
159 | data numbers; |
---|
160 | set numbers; |
---|
161 | run; |
---|
162 | proc print data=numbers noobs; |
---|
163 | title2 '4. NUMBERS dataset with lag variables replacing count and popcount'; |
---|
164 | run; |
---|
165 | |
---|
166 | data tmp; |
---|
167 | set numbers; |
---|
168 | if year>=&begyear+4; |
---|
169 | rate=count5/popcount5; |
---|
170 | if count5>0 then do; |
---|
171 | rateper=(rate*100000); |
---|
172 | stderr=sqrt(rate*(1-rate)/popcount5)*100000; |
---|
173 | end; |
---|
174 | if count5<=0 then do; |
---|
175 | rateper=0; |
---|
176 | stderr=sqrt((3/popcount5)*(1-(3/popcount5))/popcount5)*100000; |
---|
177 | end; |
---|
178 | t1=(rateper-(1.96*stderr)); |
---|
179 | if (t1<0) then t1=0; |
---|
180 | LL=put(t1, 8.2); |
---|
181 | UL=put((rateper+(1.96*stderr)), 8.2); |
---|
182 | n=count5; *ibis-q needs a count variable named 'n'; |
---|
183 | |
---|
184 | if count5>0 then do; |
---|
185 | rse=(stderr/rateper); |
---|
186 | redflag=put('', $12.); |
---|
187 | if rse>.3 then redflag=put('Unstable', $12.); |
---|
188 | if rse>.5 then redflag=put('VeryUnstable', $12.); |
---|
189 | if stderr=. then redflag=put('Unstable', $12.); |
---|
190 | end; |
---|
191 | if count5<=0 then redflag=put('Unstable', $2.); *no variance, n=0, rse=div by zero; |
---|
192 | run; |
---|
193 | |
---|
194 | proc print data=tmp noobs; title2 '5. TMP dataset for 5-year rates'; |
---|
195 | run; |
---|
196 | |
---|
197 | ************* 12. New Mexico Small Numbers Rule *******************; |
---|
198 | * Suppress cells if the numerator in (1 2 3) AND the denominator ; |
---|
199 | * is less than 5000. For Counts, must run the crude rate code to ; |
---|
200 | * capture the denominator, but only output the N. ZW's program ; |
---|
201 | * uses ".A" to identify cells for suppression. I have co-opted ; |
---|
202 | * his method so I can use the NM logic for cell suppression instead; |
---|
203 | * of the standard IBIS logic. And I need to use ZW's program ; |
---|
204 | * because it will suppress the table marginals that can be used to ; |
---|
205 | * calculate the suppressed cells. If this code is used, the .def ; |
---|
206 | * file should have the "NM_" prefix. Needs suppressed_variabes ; |
---|
207 | * code at the end of this file to work. ; |
---|
208 | *******************************************************************; |
---|
209 | /* data tmp; |
---|
210 | set tmp; |
---|
211 | if ((0<n<4) and (.<popcount5<5000)) then do; |
---|
212 | n = .A; |
---|
213 | rateper = .A; |
---|
214 | LL = put('**', 8.0); |
---|
215 | UL = put('**', 8.0); |
---|
216 | |
---|
217 | *Only one value attribute is allowed - so if suppressed, overwrite unstable; |
---|
218 | *This also puts ** in record code column for suppressed rows, and adds footnote; |
---|
219 | redflag = put('Suppressed', $12.); |
---|
220 | end; |
---|
221 | if popcount=. then redflag=put('', $12.); *no value attribute for missing crossby values; |
---|
222 | proc print data=tmp noobs; title2 '6. TMP - final dataset to pass to IBIS View app'; |
---|
223 | run; |
---|
224 | */ |
---|
225 | --------BoNdArY-------- |
---|
226 | # definition for output file |
---|
227 | f out_variable rateper |
---|
228 | f xml_out_map_file XMLRateYPLL100K.map |
---|
229 | --------BoNdArY-------- |
---|
230 | f out_detail lbl_not_used__see_xml_out_map_file |
---|
231 | rateper 15.2 |
---|
232 | n 15.2 |
---|
233 | popcount 15.2 |
---|
234 | --------BoNdArY-------- |
---|
235 | |
---|