BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Pyrite | Level 9

Hi guys, 

how can I calculate person-years from two dates for ex: 16FEB2019 and 08JAN2020? 

I have two variables with around 20.000 rows in my table. 

Thank you in advance. 

 

Best

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@NewUsrStat

Based on your very lean description the two variables with dates you want to compare are in the same row. And what is a person-year? Below assumes it's just a count of calendar years.

data demo;
  dt1='16FEB2019'd;
  dt2='08JAN2020'd;
  format dt1 dt2 date9.;

  n_calendar_years=intck('year',dt1,dt2)+1;
run;
proc print data=demo;
run;
 

Patrick_0-1714891001179.png

What could really help to explain things and remove ambiguity is if you provide some representative sample data and show us the desired result. 

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Please tell us the desired outcome for the case where the two variables have values 16FEB2019 and 08JAN2020

--
Paige Miller
NewUsrStat
Pyrite | Level 9
So I have to calculate the contribution (person years) of each patient to the study from 16FEB2019 when it was included, to 08JAN2020 the last date we have.
PaigeMiller
Diamond | Level 26

This gives the same information as before. This doesn't answer the question. How many person-years is that?

--
Paige Miller
Patrick
Opal | Level 21

@NewUsrStat

Based on your very lean description the two variables with dates you want to compare are in the same row. And what is a person-year? Below assumes it's just a count of calendar years.

data demo;
  dt1='16FEB2019'd;
  dt2='08JAN2020'd;
  format dt1 dt2 date9.;

  n_calendar_years=intck('year',dt1,dt2)+1;
run;
proc print data=demo;
run;
 

Patrick_0-1714891001179.png

What could really help to explain things and remove ambiguity is if you provide some representative sample data and show us the desired result. 

NewUsrStat
Pyrite | Level 9
Thank you very much Patrick for your help!
Tom
Super User Tom
Super User

@NewUsrStat wrote:

Hi guys, 

how can I calculate person-years from two dates for ex: 16FEB2019 and 08JAN2020? 

I have two variables with around 20.000 rows in my table. 

Thank you in advance. 

 

Best


You left out most (if not all) of the necessary information.

You probably have some data in addition to those two dates.  What does the data look like?  Show a small example (2 or three persons) and what result you want for that example data.

 

 Will you have other date ranges you want to summarize? Where will the two dates needed to define those ranges coming from? 

NewUsrStat
Pyrite | Level 9
Sorry, I know there are no details but it is also not clear to me what others asked. I will ask soon.
Quentin
Super User

proc sql ;
select sum(date2-date1)/365.25
from have
;
quit ;

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 994 views
  • 2 likes
  • 5 in conversation