BookmarkSubscribeRSS Feed
dr2014
Quartz | Level 8

Hi,

I want to convert the date value in the 'd' variable in the sas dataset 'final' such as 10/21/2012 to a sas date value and create a new variable 'd1' for it. The 'd' variable is numeric. I used the code below and it did convert the mmddyy10. formatted values to a sas value but only for the year 2012. Dates with values in the 2011 year such as 10/12/2011 were not converted. I am not able to understand this. In addition I also got the 'note' stated below in the log. Please advice. I need to find the most recent date value and coverting into sas date values will make ti easier.

Thanks,

dr

 

data temp (keep= d d1);
17    set final;
18   d1=input(d,anydtdte15.);
19   run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      18:13

5 REPLIES 5
MaikH_Schutze
Quartz | Level 8

It appears that your data variable 'd' is already in a numeric SAS date. Run the CONTENTS procedure to see if a permanent format is already assigned to variable 'd'. If so, then the actual date will show on the printed output but the underlying data is still the numeric SAS date, i.e. the number of days since January 1, 1960.

 

The log note simply documents that INPUT function performed numeric to character conversion. 

dr2014
Quartz | Level 8

Thanks @MaikH_Schutze. Yes, it did have a permanent format and I removed it.

DartRodrigo
Lapis Lazuli | Level 10

Hi mate,

 

Can you post your code as an example to work on it ?

 

Thanks

MaikH_Schutze
Quartz | Level 8

The original post already includes the code. Upon re-reading, he does say the date variable is already associated with the SAS date format mmddyy10., therefore, the raw data is already a standard SAS date number. If you'd rather have the number than remove the format using this type of code.

 

data final_2;
   set final;
   format d;
run;

  

The FORMAT statement without a format will remove a previously assigned format.

 

https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000178212.htm

dr2014
Quartz | Level 8

Thanks @MaikH_Schutze for the link. I did remove the format and it worked.

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
  • 5 replies
  • 1136 views
  • 2 likes
  • 3 in conversation