New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

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
Lapis Lazuli | Level 10
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
Lapis Lazuli | Level 10
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
Lapis Lazuli | Level 10
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 webinar will be in March 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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