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 ;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.