BookmarkSubscribeRSS Feed
learn2
Fluorite | Level 6

If I have a dataset structure like this, how can I code to determine the rate = visits/person years?

 

 

ID

Total number of Visits

Start Date

End date

1

15

Jan21,2002

April4,2008

2

4

Feb6,1991

June8,2015

3

7

June9,1999

July5,2000

5 REPLIES 5
Reeza
Super User
How are you accounting for partial years? If they're in a year at any point are they included?
learn2
Fluorite | Level 6

What do people usually do for partial years, pretty new to this and kind of unsure of how to go about this 

ballardw
Super User

@learn2 wrote:

What do people usually do for partial years, pretty new to this and kind of unsure of how to go about this 


Person years can change between usage groups possibly even within an organization on a per topic basis.

 

One possible way would be to use the YRDIF function with the two dates in question with the "ACT/ACT" basis as that returns years with a decimal portion.

data example;
   years= yrdif('21MAR1987'd,'17Jul2001'd,'ACT/ACT');
run;

for example returns approximately 14.323 years.

learn2
Fluorite | Level 6

Thanks!

SuryaKiran
Meteorite | Level 14

Hello,

 

This might help:

data have;
input ID Visits Start :$15. End :$15.;
datalines;
1 15 Jan21,2002 April4,2008
;
run;

data want;
set have;
start_date=input(cats(compress(scan(start,1,','),,'a'),substr(start,1,3),scan(start,2,',')),date9.);
end_date=input(cats(compress(scan(end,1,','),,'a'),substr(end,1,3),scan(end,2,',')),date9.);
years=int((end_date-start_date)/365.24);
run;

Please provide your sample data in the form of datastep.

Thanks,
Suryakiran

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 1204 views
  • 3 likes
  • 4 in conversation