BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lmyers2
Obsidian | Level 7

Hello

 

I'm trying to find the number of years between 2 dates. The variables have the following attributes. I'm not sure why the code I have below isn't working.

 

                              Length  Format    Informat   Label

lmyers2_0-1616287206443.png

lmyers2_1-1616287269045.png

 

 

data want; set have;

length=year(datepart(EVRPRDTTM))-year(datepart(adate));

run;

The date is arranged in columns. There is only 1 row per patient.

                     adate    EVRPRDTTM

Patient 1

Patient 2

Patient 3...

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Looks like ADATE is a date not a datetime variable so try this and switch to the INTCK function for greater accuracy:

data want; set have;

length=intck('YEAR', adate, datepart(EVRPRDTTM), 'C');
run;

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

Looks like ADATE is a date not a datetime variable so try this and switch to the INTCK function for greater accuracy:

data want; set have;

length=intck('YEAR', adate, datepart(EVRPRDTTM), 'C');
run;
lmyers2
Obsidian | Level 7
Thanks - what does the C do in the code?
SASKiwi
PROC Star

@lmyers2  - It's explained in the link I included (C = CONTINUOUS). If you still don't follow after reading that then please advise.

Tom
Super User Tom
Super User

The DATEPART() function is for converting datetime values (seconds) into date values (days).  It is essentially doing a MOD() operation with number of seconds in a day.  If you give a date value, like you are doing the result will be zero, which is 01JAN1960, since there are more seconds in a day than there are days since 1960 to now.

1460  data _null_;
1461    today=date();
1462    day = '24:00't ;
1463    put (_all_) (=comma12.);
1464  run;

today=22,361 day=86,400

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
  • 4 replies
  • 934 views
  • 0 likes
  • 3 in conversation