to convert a date variable - xdate to SAS date values like 20340 . Xdate has values -12SEP2015 and xdate is of numeric and format date9
If D is an integer number of days then just add it.
newdate = olddate + d ;
If you want to add other intervals (months, weeks) then you should look at the INTNX() function.
newdate = intnx('day',olddate,d);
newdate = intnx('month',olddate,m,'same');
data have;
date_have='12SEP2015'd;
format date_have date9.;
date_want=date_have;
run;
proc print data=have;
run;
How can i add d to my date value.
If D is an integer number of days then just add it.
newdate = olddate + d ;
If you want to add other intervals (months, weeks) then you should look at the INTNX() function.
newdate = intnx('day',olddate,d);
newdate = intnx('month',olddate,m,'same');
So if the variable is of type NUM and has a format DATE9 applied and the values when printed look like valid dates, such as '12SEP2015' then it already IS and number. In fact if the value is '12SEP2015'd then the number in the XDATE variable is 20,343.
There is nothing to "convert".
Tom,
The vales in Xdata re of 12SEP2015, 01OCT2015. when i try to assign it to new variable ydate i need to get the number but i am getting empty values.
ydate = datepart(xdate); - didnt work.
tried others too.
The DATEPART() function converts a DATETIME value (number of seconds) to a DATE value (number of days). So basically you divided your date by 86,400 (24hr*60min/hr*60sec/min)
ydate = xdate ;
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.
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.