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

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
Quartz | Level 8
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
Quartz | Level 8
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
Quartz | Level 8
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 ;

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 378 views
  • 2 likes
  • 5 in conversation