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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 874 views
  • 0 likes
  • 3 in conversation