BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
adityaa9z
Obsidian | Level 7

Hi Can someone help me with using the informat for this date ?

 

Feb  5 2019 12:00AM

 

Also I need the output in mmddyy10. format?

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

If your datetime comes in this form consistently, the anydtdtm. informat will work:

data want;
indate = 'Feb  5 2019 12:00AM';
outdate = datepart(input(indate,anydtdtm20.));
format outdate mmddyy10.;
run;

proc print data=want noobs;
run;

Result:

      indate              outdate

Feb  5 2019 12:00AM    02/05/2019

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

So you want to read the string "Feb  5 2019 12:00AM" as a date or a datetime value?

adityaa9z
Obsidian | Level 7
Want to read it as DateTime. Want to Write as mmddyy10.
Kurt_Bremser
Super User

If your datetime comes in this form consistently, the anydtdtm. informat will work:

data want;
indate = 'Feb  5 2019 12:00AM';
outdate = datepart(input(indate,anydtdtm20.));
format outdate mmddyy10.;
run;

proc print data=want noobs;
run;

Result:

      indate              outdate

Feb  5 2019 12:00AM    02/05/2019
ballardw
Super User

If you want to keep the value as a datetime value you can use a custom format. Example:

Proc format library=work;
picture dtmmddyy    (default=10)
low-high ='%0m/%0d/%Y'   (datatype=datetime)
;
run;

data example;
   x='02FEB2019:10:15:15'dt;
   put x dtmmddyy.;
run;

SAS does supply a number of other formats to display the date portion of datetime values such as DTDATE, DTMONYY and a couple of others. So this is not an off the wall solution.