Skip to content

Instantly share code, notes, and snippets.

@statgeek
Last active August 16, 2023 10:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save statgeek/9606454 to your computer and use it in GitHub Desktop.
Save statgeek/9606454 to your computer and use it in GitHub Desktop.
SAS - Standardized Rates
/*This program illustrates how to age standardize rates using the age data for Canada 1991*/
*Source Data:http://www.apheo.ca/resources/indicators/Standardization%20report_NamBains_FINALMarch16.pdf
*Source Code:http://support.sas.com/documentation/cdl/en/statug/65328/HTML/default/viewer.htm#statug_stdrate_syntax01.htm
;
*Create dataset with Canada Standard Rates for 1991;
data CanadaSTDRATE;
format AgeGroup 2. AgeGroupDesc $5. Canada1991 comma12.;
informat Canada1991 comma12.;
input AgeGroup AgeGroupDesc $ Canada1991;
cards;
1 0-4 1,953,346
2 5-9 1,953,045
3 10-14 1,913,115
4 15-19 1,926,090
5 20-24 2,109,452
6 25-29 2,529,239
7 30-34 2,598,289
8 35-39 2,344,872
9 40-44 2,138,891
10 45-49 1,674,153
11 50-54 1,339,902
12 55-59 1,238,441
13 60-64 1,190,217
14 65-69 1,084,588
15 70-74 834,024
16 75-79 622,221
17 80-84 382,303
18 85-89 192,410
19 90+ 95,467
;
run;
*Create sample data set with raw event numbers and population numbers;
data study_data;
format AgeGroup 8. events population comma12.;
input AgeGroup events population;
cards;
1 37 756055
2 25 760339
3 23 740079
4 27 721396
5 47 747171
6 66 826426
7 122 994837
8 264 973239
9 443 865317
10 731 790269
11 1022 608638
12 1523 501218
13 2223 459365
14 3108 431223
15 3866 374246
16 3345 255754
17 2719 167495
18 1692 85585
19 906 42224
;
run;
*Example of standardization rates;
*Expected value out is 187.1 95% CI(184.7, 189.1);
ods table STDRATE=EX_STDRATE; /*Store results in dataset if needed*/
proc stdrate data=study_data /*Specify data that contains events and population*/
refdata=CanadaSTDRATE /*Specify dataset that contains reference population*/
method=direct /*Specify the method of standardizaton*/
stat=rate (mult=100000) /*Specify that the stat of interest is Rate(vs Risk) and per 100,000 population*/
CL=Normal /*Specify the type of CI required - Gamma, lognormal, none, normal, poisson*/
;
population event=events total=population; /*Specify variables from event data*/
reference total=Canada1991; /*Specify the population variable from the reference data*/
strata agegroup; /*Specify the category (ie age group)*/
run;
*If needed to run this for multiple diseases at once, ADD GROUP=VARIABLE to the population statement. This won’t run, I don’t have sample data for it;
proc stdrate data=study_data /*Specify data that contains events and population*/
refdata=CanadaSTDRATE /*Specify dataset that contains reference population*/
method=direct /*Specify the method of standardizaton*/
stat=rate (mult=100000) /*Specify that the stat of interest is Rate(vs Risk) and per 100,000 population*/
;
population group=DISEASE event=events total=population; /*Specify variables from event data and BY GROUP, where you need a different rate for each group*/
reference total=Canada1991; /*Specify the population variable from the reference data*/
strata agegroup; /*Specify the category (ie age group)*/
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment