/*PROGRAM NAME: Freq_with_SE_multiyear*/ /*This program get frequencies with standard error of ED initial injury visits by five year age groups and sex using data from 2003 through 2004*/ /*Data used in the example are all located in SAS work folder, you will need to create the data from your ED data file. The source data files were named as "ED03" and "ED04" for ED data in 2003 and 2004.*/ DATA ED_1YR; SET ED03 ED04 /*Name of source data file*/; /*The following codes were copied from instruction 6: SAS statements for identifying injury record*/ /*defining injury records*/ /*SAS statements for 2001-2004*/ /*CAUSE1 and DIAG1 are variable names used in the original SAS input statement provided by NCHS which you will get automatically if you follow steps in instruction 3. CAUSE1 is the variable for "Cause of injury #1" DIAG1 is the variable for "Physician's diagnosis #1" EPISODE is the variable for "Episode of care" EPISODE=1 indicates initial visit */ CAUSEDET=substr(left(CAUSE1),1,3); DX13=substr(left(DIAG1),1,3); DX14=substr(left(DIAG1),1,4); DX15=substr(left(DIAG1),1,5); /*defining external cause of injury*/ EXTINJ=0; IF '800'<=CAUSEDET<='869' OR '880'<=CAUSEDET<='929' OR '950'<=CAUSEDET<='999' THEN EXTINJ=1; IF ('870'<=CAUSEDET<='879') OR ('930'<=CAUSEDET<='949') THEN EXTINJ=2; /*defining first listed injury diagnosis*/ NEWINJ=0; IF ('8000'<= DX14<='9092') OR DX14='9094' OR ('9099'<=DX14<='9949') OR ('99550'<=DX15<='99559') OR ('99580'<=DX15<='99585') THEN NEWINJ=1; IF DX13 < '800' or DX13 > '999' THEN NEWINJ=2; /* defining injury records */ INJSPB=0; IF EPISODE=1 AND ((NEWINJ=1 AND (EXTINJ =1 OR EXTINJ=0)) OR (NEWINJ=2 AND EXTINJ=1)) THEN INJSPB=1; /*End of codes copied from instruction 5*/ FORMAT _ALL_; Proc format; value agea 0-4=" 1" 5-9=" 2" 10-14=" 3" 15-19=" 4" 20-24=" 5" 25-29=" 6" 30-34=" 7" 35-39=" 8" 40-44=" 9" 45-49="10" 50-54="11" 55-59="12" 60-64="13" 65-69="14" 70-74="15" 75-79="16" 80-84="17" 85-100="18"; value ageb 1=" 1. Age 0-4" 2=" 2. Age 5-9" 3=" 3. Age 10-14" 4=" 4. Age 15-19" 5=" 5. Age 20-24" 6=" 6. Age 25-29" 7=" 7. Age 30-34" 8=" 8. Age 35-39" 9=" 9. Age 40-44" 10="10. Age 45-49" 11="11. Age 50-54" 12="12. Age 55-59" 13="13. Age 60-64" 14="14. Age 65-69" 15="15. Age 70-74" 16="16. Age 75-79" 17="17. Age 80-84" 18="18. Age 85+"; DATA ED_5YR; SET ED_1YR; /*Recode AGE into 5 year age groups, the program can be altered to calculate different age group by changing the above format "AGEA"*/ AGE5YR=(PUT(AGE, AGEA.))*1; FORMAT _ALL_; /*Sort data for SUDAAN*/ PROC SORT DATA=ED_5YR; BY CSTRATM CPSUM; /*Create file "TEMP5YR" with data on weighted ED visit counts by five year of age and sex*/ PROC CROSSTAB DATA=ED_5YR DESIGN=WR FILETYPE=SAS; NEST CSTRATM CPSUM/MISSUNIT; /*Selecting ED initial injury visits*/ SUBPOPN INJSPB=1; WEIGHT PATWT; Class AGE5YR SEX; Tables AGE5YR*SEX; OUTPUT NSUM WSUM SEWGT/ FILETYPE=SAS FILENAME=TEMP5YR replace; run; /*Transfer ED visit data into structrue similar to population data for rate calculation*/ DATA VISIT5YR(KEEP=AGE TNSUM TWSUM TSEWGT MNSUM MWSUM MSEWGT FNSUM FWSUM FSEWGT); MERGE TEMP5YR(WHERE=(SEX=0) RENAME=(NSUM=TNSUM WSUM=TWSUM SEWGT=TSEWGT)) TEMP5YR(WHERE=(SEX=2) RENAME=(NSUM=MNSUM WSUM=MWSUM SEWGT=MSEWGT)) TEMP5YR(WHERE=(SEX=1) RENAME=(NSUM=FNSUM WSUM=FWSUM SEWGT=FSEWGT)) ; BY AGE5YR; IF _c1 NE 0; /*If you changed your age group, remember to change format "AGEB" in the Proc format*/ AGE=PUT(AGE5YR, AGEB.); Label TWSUM="Bothsexes, Weighted ED visits" TSEWGT="Bothsexes SE, Weighted ED visits" MWSUM="Male, Weighted ED visits" MSEWGT="Male SE, Weighted ED visits" FWSUM="Female, Weighted ED visits" FSEWGT="Female SE, Weighted ED visits"; RUN; PROC PRINT DATA=VISIT5YR; RUN; /*"VISIT5YR" is the name of dateset that has frequencies needed for rate calculation. You can export it into EXCEL format and using the population data we provided to calculate rates. Standard errors for rates can be calculated by dividing standard errors of weighted frequencies by population. Population in this example is 2003 and 2004 combined*/