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

As part of a large data set, 2 of my columns contain dates that I want to subtract to get the difference in number of days

 

For example (imagine 1000+ rows):

Person         Column B     Date_Start    Date_End    Column E

   A                                        1/1/17          1/9/17

   B                                        3/3/17          3/6/17

   C                                        2/7/17          2/12/17

   D                                        8/8/17          8/8/17

   E                                        9/1/17          9/30/17

 

How do I subtract Date_End from Date_Start columns to get:

 

Date_Difference

           8

           3

 

           5

           0

          29

 

I've tried proc sql where I've assigned the following, but this doesn't seem right:

     min(Date_Start) as Date_Start,
     max(Date_End) as Date_End,
     max(Date_End) - min(Date_Start) as Date_Difference,

 Also had a go with (preferred code layout):

data timing;
set timing;
by Person;
   Date_Difference = intck('Date_Difference', Date_Start, Date_End);
   put Date_Difference = ;
run;

Any help with the coding would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12
  select Date_End - Date_Start as Date_Difference,

the above code should work

View solution in original post

3 REPLIES 3
kiranv_
Rhodochrosite | Level 12
  select Date_End - Date_Start as Date_Difference,

the above code should work

Reeza
Super User

Dates can be subtracted directly to get the number of days, either in SQL or the data step. If you're going to use INTCK, the interval, which is the first parameter is 'DAY'

Astounding
PROC Star

If your dates are actually character strings rather than true SAS dates, you would need:

 

data want;

set timing;

date_difference = input(Date_End, mmddyy8.) - input(Date_Begin, mmddyy8.);

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 878 views
  • 1 like
  • 4 in conversation