BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Paulukonis
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

9 REPLIES 9
ballardw
Super User

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.

 

 

Reeza
Super User

Please post expected output for your sample data.

Paulukonis
Calcite | Level 5

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. 

Reeza
Super User

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. 

Paulukonis
Calcite | Level 5

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?

Ksharp
Super User

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;
Paulukonis
Calcite | Level 5

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

Reeza
Super User

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;
Paulukonis
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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