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
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;
What could really help to explain things and remove ambiguity is if you provide some representative sample data and show us the desired result.
Please tell us the desired outcome for the case where the two variables have values 16FEB2019 and 08JAN2020
This gives the same information as before. This doesn't answer the question. How many person-years is that?
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;
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 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?
proc sql ;
select sum(date2-date1)/365.25
from have
;
quit ;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.