BookmarkSubscribeRSS Feed
chris_nguyen
Calcite | Level 5

I'm having trouble converting from a DATETIME20. format to a MMDDYY10. format. Whenever I try to to edit my table with PROC SQL code (or equivalent PROC DATASETS code) such as the one given here:

 

proc sql;
alter table table1
modify datetime_to_date format=mmddyy10.;
quit;

 

All I get is a column full of '**********'s. I can convert to a numeric date format and can convert back to DATETIME20. all right but how can I permanently change the format to MMDDYY10. format correctly?

1 REPLY 1
Reeza
Super User

You need to do a calculation. A datetime is the number of seconds from Jan 1, 1960, while a date variable is the number of days. 

 

To do the conversion you can use the datepart() function in a proc sql or data step, but not in proc datasets or via an alter table.

 

If you just want to change the display format of your data you can use DTDATE9. or a format in that family. Unfortunately I don't think there's one that matches the format you want though you can always create your own if you'd like, see Picture formats. 

 

 

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
  • 1 reply
  • 1918 views
  • 0 likes
  • 2 in conversation