Formatting of Date

Posts: 39

Formatting of Date

Hello Members,

I need some help on formatting a sas date. I have character field E_Date_Time, where values are in the format "9/1/2011 9:25:36". Now, I need the values in date format as "09/01/2011 09:25:36". My code is not working the way I want it to work. I am trying to extract the date and time from E_Date_Time, format them separately and attach them back. The date and time can be separated by ':' or space.

data want:

     format E_Date mmddyy10.;

set have;

E_Date=input(tranwrd(E_Date_Time, ' 0:00:00', ' '), mmddyy10.);

E_Time=scan(E_Date_Time, -1,' ');

E_Date_Time_New=catx(':', E_Date, E_Time);


The result  of var E_Date_Time_New for the above mentioned value is:


Thank you for your time.

Posts: 65

Re: Formatting of Date

In SAS all the dates will be in numeric format that's the reason you are getting value as 18871 in the code above. Just try the below code you will be getting the proper date.

E_Date=input(E_Date_Time, mmddyy10.);

E_Time=scan(E_Date_Time, -1,' ');

E_Date_Time_New=catx(':',put(E_Date, mmddyy10.), E_Time);

In the third statement I have converted the numric date to character date again, so that you will get the required date format value.


Moovendhan D

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation