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

to convert a date  variable - xdate  to SAS date values like 20340 . Xdate has values -12SEP2015 and xdate is of numeric and format date9

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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');

View solution in original post

6 REPLIES 6
stat_sas
Ammonite | Level 13

data have;
date_have='12SEP2015'd;
format date_have date9.;
date_want=date_have;
run;

 

proc print data=have;
run;

archana
Fluorite | Level 6

How can i add d to my date value.

Tom
Super User Tom
Super User

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');
Tom
Super User Tom
Super User

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".

archana
Fluorite | Level 6

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.

Tom
Super User Tom
Super User

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 ;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 3558 views
  • 2 likes
  • 3 in conversation