Long SAS Date to Shorter Output Date

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Long SAS Date to Shorter Output Date

I have a column titled "Birth_Date" with long SAS date values.

 

The dates look like this: 01MAR1993:00:00:00

 

All I want is to convert those values to the following format: 01-MAR-1993.

 

So, long story short. I just want to convert the date to a different format. I've seen other solutions that are close, but I can't seem to get to the finish line on this one. Spare me the judgment please Smiley Happy


Accepted Solutions
Solution
‎01-22-2018 09:31 AM
Super User
Posts: 9,931

Re: Long SAS Date to Shorter Output Date

Posted in reply to mgmatyasovsky

Convert the datetime value to a date:

birth_date = datepart(birth_date);
format birth_date date11.;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Respected Advisor
Posts: 2,841

Re: Long SAS Date to Shorter Output Date

Posted in reply to mgmatyasovsky

Use the DATE11. format.

--
Paige Miller
Solution
‎01-22-2018 09:31 AM
Super User
Posts: 9,931

Re: Long SAS Date to Shorter Output Date

Posted in reply to mgmatyasovsky

Convert the datetime value to a date:

birth_date = datepart(birth_date);
format birth_date date11.;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 3

Re: Long SAS Date to Shorter Output Date

Posted in reply to KurtBremser

Perfect!  Thank you so much!

Super User
Super User
Posts: 7,943

Re: Long SAS Date to Shorter Output Date

Posted in reply to mgmatyasovsky

You can use the DTDATE format to print just the date part of a datetime value, but it does not support printing the hyphens.

Or you could convert your datetime value (number of seconds) into a date value (number of days) and then use the DATE11. format.

287  data _null_;
288    dt='01MAR1993:00:00:00'dt;
289    date=datepart(dt);
290    put dt= dt datetime20. +1 dt dtdate9. ;
291    put date=  date date11. ;
292  run;

dt=1046563200   01MAR1993:00:00:00 01MAR1993
date=12113 01-MAR-1993
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 107 views
  • 2 likes
  • 4 in conversation