Hello,
I am trying to calculate age-adjusted mortality rates for a region using the code below:
proc stdrate data = traumadeaths
refdata = ncipop
method = direct
stat = rate(mult = 100) ;
population event = died total = population ;
reference total = population;
strata agegrp /stats;
by edayr;
ods output stdrate = MorRates stRatastats=tester;
Run;
I am getting an error message:
ERROR: The observation values for the TOTAL= variable in the POPULATION statement must be positive.
Can anyone please explain to me what does this error mean?
Thank you 🙂
My basic approach would be to write a custom format mapping the existing values to a new group and use that in proc summary to get new totals.
Something like this:
data want; set have; by group; diftime= dif(time); meanrate= mean(lag(rate),rate); if not first.group then value=diftime*meanrate; drop diftime meanrate; run; proc format library=work; value combineage 1,2,3 = '1-3' 4 = '4' 5 = '5' 6 = '6' ; run; proc summary data=eventdata nway; class agegrp; format agegrp combineage. ; var eventvar populationvar; output out=combinedevent (drop=_:) sum=; run; proc summary data=refernecedata nway; class agegrp; format agegrp combineage. ; var eventvar populationvar; output out=combinedrefernece (drop=_:) sum=; run;
The format combines 3 agegroup levels (in this case numeric) into one leaving the others alone.
Then use the combinedevent and combinedreference data sets in Proc Stdrate.
The choice of which levels to combine might depend on which are missing and other knowledge. If the strata are age almost certainly the combinations should represent adjacent ages. The number and pattern of 0 population might bring some art into question and it might be worth trying different formats (one of the reasons to use such, make a different format such as
proc format library=work; value combineage_2nd 1,2 = '1-2' 3,4 = '3-4' 5 = '5' 6 = '6' ; run;
change the format used in the Proc summary to use combineage_2nd. and then run the summary and stdrate code.
Do you have any missing, negative or 0 values for Population in either of your Data= or Refdata= data sets?
No missings or negatives but many zeros. There weren't many deaths in that data set
@Ihsan-Mahdi wrote:
No missings or negatives but many zeros. There weren't many deaths in that data set
I would expect EVENTS to possibly be 0. What about the POPULATION variable, as in the number of people in the population for that age strata? Zero for population would indicates that there were no people at all in that age stratification and makes not sense to include in the analysis.
I would question why the population is zero in the first place. If looking at a small geographic area then perhaps it makes sense.
I suspect the best approach would be to combine age strata in both the Event and Reference population data so that there is a population >0 in each of the Event and Reference data sets.
A quick experiment with an example in the documentation show things like poulations-time, crude rate , reference crude rate and some estimates can change just dropping one of the strata even when both event and population reference data have 0 counts for the event.
My basic approach would be to write a custom format mapping the existing values to a new group and use that in proc summary to get new totals.
Something like this:
data want; set have; by group; diftime= dif(time); meanrate= mean(lag(rate),rate); if not first.group then value=diftime*meanrate; drop diftime meanrate; run; proc format library=work; value combineage 1,2,3 = '1-3' 4 = '4' 5 = '5' 6 = '6' ; run; proc summary data=eventdata nway; class agegrp; format agegrp combineage. ; var eventvar populationvar; output out=combinedevent (drop=_:) sum=; run; proc summary data=refernecedata nway; class agegrp; format agegrp combineage. ; var eventvar populationvar; output out=combinedrefernece (drop=_:) sum=; run;
The format combines 3 agegroup levels (in this case numeric) into one leaving the others alone.
Then use the combinedevent and combinedreference data sets in Proc Stdrate.
The choice of which levels to combine might depend on which are missing and other knowledge. If the strata are age almost certainly the combinations should represent adjacent ages. The number and pattern of 0 population might bring some art into question and it might be worth trying different formats (one of the reasons to use such, make a different format such as
proc format library=work; value combineage_2nd 1,2 = '1-2' 3,4 = '3-4' 5 = '5' 6 = '6' ; run;
change the format used in the Proc summary to use combineage_2nd. and then run the summary and stdrate code.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.