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

How do I compute the # of days from date to date. 

I have sample data: 

Obs.  date1       date2           date3        date4

1       1/1/2010   2/10/2010   3/10/2010  4/5/2010

2       5/3/2011  5/5/2011      5/15/2010

 

I want output data: 

Obs.  date1       date2           date3        date4        daysdif1    daysdif2   daysdif3  

1       1/1/2010   2/10/2010   3/10/2010  4/5/2010        40            28             26

2       5/3/2011  5/5/2011      5/15/2010                         2              10 

 

Any help using would be great. 

thanks

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
infile cards truncover;
input Obs  (date1       date2           date3        date4) (:mmddyy10.);
format date: mmddyy10.; cards; 1 1/1/2010 2/10/2010 3/10/2010 4/5/2010 2 5/3/2011 5/5/2011 5/15/2011 ; data want; set have; array t(*) date:; array daysdif(3); do _n_=2 to dim(t); daysdif(_n_-1)=t(_n_)-t(_n_-1); end; run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data have;
infile cards truncover;
input Obs  (date1       date2           date3        date4) (:mmddyy10.);
format date: mmddyy10.; cards; 1 1/1/2010 2/10/2010 3/10/2010 4/5/2010 2 5/3/2011 5/5/2011 5/15/2011 ; data want; set have; array t(*) date:; array daysdif(3); do _n_=2 to dim(t); daysdif(_n_-1)=t(_n_)-t(_n_-1); end; run;
127
Fluorite | Level 6 127
Fluorite | Level 6
Perfect, thanks so much!

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 354 views
  • 1 like
  • 2 in conversation