Contributor
Posts: 40

# Need help on SAS code for calculating person years to use as denominators to calculate crude rates

I have a dataset of 25000 records with this layout;

ID         DOC1 DOC2    DOC4    DOC48  Month_death year_death     race      age       gender

1               0         1            0                  0              4                 2014             1            45           F

DOC1-DOC48 have 0 if the person was on the streets, 1 if incarcerated

DOC1 corresponds to January 2011

DOC48 corresponds to December 2014

Death records are from Jan 2013 to Dec 2014. We only have month and year.

so for this person id #1, she was incarcerated on February 2011 and has been out on the streets since April 2011. I need to count her "street" time as the actual time at risk for dying- DOC1, DOC4-DOC48 -46 months. Need to do this for all records.

I will need to calculate time to death for those that died and time to end of study (Dec 2014) for everyone else for a survival analysis And finally fill-in this table for those that died.

 Number of deaths Persons-Years at Risk CMR per 100 person years 1 month 3 months 6 months 1 year 2 year All deaths

Super User
Posts: 23,749

## Re: Need help on SAS code for calculating person years to use as denominators to calculate crude rat

What happens if there is no death during the period, how is the date represented? I'm assuming month_death/year_death are numeric.

``````if  month_death ne . then end=mdy(month_death, 1, year_death);
else end=mdy(12, 1, 2014);

n_months=intck('month', "01Jan2013"d, end);
on_street = n_months - sum(of doc1-doc48);``````
Contributor
Posts: 40

## Re: Need help on SAS code for calculating person years to use as denominators to calculate crude rat

Thanks Reeza, if there are no deaths, then the end of the study period is December 2014. And yes these are numeric
Discussion stats
• 2 replies
• 605 views
• 0 likes
• 2 in conversation