Calculating Person-Years by Age

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Calculating Person-Years by Age

Using 9.3. My data are in 1 case per row format, with case ID and three dates: dob (dob), entry into cohort(first_dt), exit from cohort(last_dt). For context, the study spanned 10 years, so typical rows would be:

id dob        first_dt   last_dt
1 05MAR1980 01JAN2005 31DEC2014 (alive throughout study)
2 12AUG2006 12AUG2006 31DEC2014 (born during study)
3 19SEP1975 01JAN2005 20MAY2011 (died or censored during study)

 

I need the amount of time the cohort has spent in one year age increments. For instance, how many total person years spent at age less than 1, how many total PYs at age 1, at age 2, etc. over the course of the study?

 

I'm fairly certain there's a simple way to do this (perhaps a table that can be output in a survival analysis?) but after several hours of trying to find a simple solution, I'm stumped. Thanks for any help you can provide.

 

S


Accepted Solutions
Solution
‎04-28-2016 12:35 AM
Super User
Posts: 10,041

Re: Calculating Person-Years by Age

Posted in reply to Paulukonis

I have no time to go through all of these . Just give you some code to guide you how to solve this question.

 

data _null_;
dob='05MAR1980'd;
first_dt='01JAN2005'd;
last_dt='31DEC2014'd;


  x=yrdif(dob,first_dt,'act/act');
  age=int(x);
  x=ceil(x)-x;
  put x 'at age' age;


  do j=intck('year',dob,first_dt,'c')+1 to intck('year',dob,last_dt,'c')-1;
    put '1 at age' j;
  end;


  x=yrdif(dob,last_dt,'act/act');
  age=int(x);
  x=mod(x,1);
  put x 'at age' age;
run;

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Calculating Person-Years by Age

Posted in reply to Paulukonis

Provide some example output. It seems as though you may be asking for multiple output variables.

And there appears to be a dependence on an unstated value: when the study began.

 

I am also not sure that anyone would ever have more than one person year at "age less than one", so there may be some other information not explicitly stated there as well such as you are summarizing after the "years" are calculated.

 

 

Super User
Posts: 19,855

Re: Calculating Person-Years by Age

Posted in reply to Paulukonis

Please post expected output for your sample data.

Occasional Contributor
Posts: 5

Re: Calculating Person-Years by Age

Expected output would be

total_cohort_person_years_age_0= XX.X years

total_cohort_person_years_age_1 = XX.X years

total_cohort_person_years_age_2 = XX.X years

etc, to age 99

 

 

This can be done on a per row/case basis and then I can sum using proc sql, but I'm thinking there may be a simpler way to do this, as I said.

 

 

First date of study was 1/1/2005, but it shouldn't matter since I have entry(first_dt) in cohort and exit from(last_dt) cohort for each person. 

Super User
Posts: 19,855

Re: Calculating Person-Years by Age

Posted in reply to Paulukonis

Sorry, I don't understand your output. Ideally you should provide a sample input and sample output that has the calculations done so we're not assuming things. 

Occasional Contributor
Posts: 5

Re: Calculating Person-Years by Age

Person years (PY) at age X = time patient spent in study in years at a particular age point (age 1 year, age 2 years, etc.)

 

id dob        first_dt   last_dt
1 05MAR1980 01JAN2005 31DEC2014 (alive throughout study)
2 12AUG2006 12AUG2006 31DEC2014 (born during study)
3 19SEP1975 01JAN2005 20MAY2011 (died or censored during study)

Case ID 1

Total of 10 PY in study. 24.83 years of age at first_dt. 

Desired output:

.17 PY at age 24

1.00 PY at age 25

1.00 PY at age 26

1.00 PY at age 27

1.00 PY at age 28

1.00 PY at age 29

1.00 PY at age 30

1.00 PY at age 31

1.00 PY at age 32

1.00 PY at age 33

.83 PY at age 34

 

Case ID 2 was 0 at first_dt (her birth date). She spent 1.00 PY at age 0, 1.00 PY at age 1, 1.00 PY at age 2, 1.00 PY at age 3, 1.00 PY at age 4, 1.00 PY at age 5, 1.00 PY at age 6, 1.00 PY at age 7, and .39 PY at age 8. Total of 8.39 PY in study.

 

Case ID 3 was 29 at age of first_dt. She spent .71 PY at age 29, 1.00 PY at age 30, 1.00 PY at age 31, 1.00 PY at age 32, 1.00 PY at age 33, 1.00 PY at age 33, .67 PY at age 34. Total of 6.38 PY.

 

Does that clarify?

Solution
‎04-28-2016 12:35 AM
Super User
Posts: 10,041

Re: Calculating Person-Years by Age

Posted in reply to Paulukonis

I have no time to go through all of these . Just give you some code to guide you how to solve this question.

 

data _null_;
dob='05MAR1980'd;
first_dt='01JAN2005'd;
last_dt='31DEC2014'd;


  x=yrdif(dob,first_dt,'act/act');
  age=int(x);
  x=ceil(x)-x;
  put x 'at age' age;


  do j=intck('year',dob,first_dt,'c')+1 to intck('year',dob,last_dt,'c')-1;
    put '1 at age' j;
  end;


  x=yrdif(dob,last_dt,'act/act');
  age=int(x);
  x=mod(x,1);
  put x 'at age' age;
run;
Occasional Contributor
Posts: 5

Re: Calculating Person-Years by Age

Wonderful! I needed the intck function, and didn't know it. Thanks for setting up for me so nicely.

Super User
Posts: 19,855

Re: Calculating Person-Years by Age

Posted in reply to Paulukonis

Do you need the value for each year or just the total? 

 

The total is relatively easily to calculate using the yrdif function, but if you want it for each age and the duration its a bit more work. 

 

This should get you started though:

 

data have;
informat dob first_dt last_dt anydtdte.;
input id dob        first_dt   last_dt;
cards;
1  05MAR1980  01JAN2005  31DEC2014
2  12AUG2006  12AUG2006  31DEC2014
3  19SEP1975  01JAN2005  20MAY2011
;
run;

data want;
set have;
py=yrdif(first_dt, last_dt+1, 'act/act');
format py 8.2 first_dt last_dt dob date9.;
run;

proc print data=want;
run;
Occasional Contributor
Posts: 5

Re: Calculating Person-Years by Age

Thanks - yes, I need it for each age, unfortunately. But I think we've solved it. I appreciate your time and input.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 516 views
  • 0 likes
  • 4 in conversation