BookmarkSubscribeRSS Feed
jenim514
Pyrite | Level 9

Hi,

Changing date formats are so confusing!

 

I would like help changing a DOB format that is a SAS date, (e.g. 17673) to a meaningful date such as date10. 

 

Thank you!

 

 

6 REPLIES 6
slchen
Lapis Lazuli | Level 10


data _null_;
date= 17673;
date1=put(date,date9.);
date2=date;
format date2 date9.;
put _all_;
run;

jenim514
Pyrite | Level 9

 

data encounterdate;

set fy14merge;

dob1=input(dob,???);

format dob1 date10.;

run;

 

THis is the code I am trying to use...but not sure what to put in the ??? if I am working with a SAS date (e.g. 19632)

Reeza
Super User
PUT() converts your date from a SAS DATE to a TEXT field.
Applying a format via the FORMAT statement changes how SAS displays the date, ie the underlying value is 19632, but it appears as 01Oct2013. Keeping the date as a SAS date allows you to use all the date functions in SAS in the future, for example, MONTH(), YEAR() to extract portions of the date. As well as it will sort properly in time, whereas if it's a character variable it will sort alphabetically.

Short version: Apply a format, don't use PUT() to convert.
jenim514
Pyrite | Level 9

Thank you!

jenim514
Pyrite | Level 9

data encounterdate; set fy14merge; dob1=input(dob,???); format dob1 date10.; run; THis is the code I am trying to use...but not sure what to put in the ??? if I am working with a SAS date (e.g. 19632)

Reeza
Super User


data encounterdate; 
set fy14merge; 
format dob date9.; 
run; 

Try the above. Also, please take the time to format your code properly.  

You don't need input unless the value is a character and it seems to be a number. 

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
  • 6 replies
  • 992 views
  • 1 like
  • 3 in conversation