BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
buddha_d
Pyrite | Level 9
SAS gurus
How to convert date as 06/12/2016 4:30:55 PM (Char 22) From

12JUN16:16:30:55 (numeric 8 information)?

I used informat mdyampm. But it truncates the seconds
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
proc format library=work;
picture Exceldt (default=22)
low-high = '%0m/%0d/%Y %h:%0M:%0S %p' (datatype=datetime);
run;

data _null_;
   x = '12JUN16:16:30:55';
   d = input(x,anydtdtm.);
   put  d= ExcelDt.;
run;

View solution in original post

7 REPLIES 7
data_null__
Jade | Level 19

The informat creates the correct datetime value.  MDYAMPM format does not appear to show seconds but you can see they are there when displayed with DATETIME format.

 

27         data _null_;
28            x = '06/12/2016 4:30:55 PM';
29            d = input(x,mdyampm22.);
30            put x= d=mdyampm27. d=datetime.;
31            run;

x=06/12/2016 4:30:55 PM d=6/12/2016  4:30 PM d=12JUN16:16:30:55
buddha_d
Pyrite | Level 9
Input should be 12JUN16:16:30:55 and output should look like 06/12/2016 4:30:55 PM
ballardw
Super User
proc format library=work;
picture Exceldt (default=22)
low-high = '%0m/%0d/%Y %h:%0M:%0S %p' (datatype=datetime);
run;

data _null_;
   x = '12JUN16:16:30:55';
   d = input(x,anydtdtm.);
   put  d= ExcelDt.;
run;
buddha_d
Pyrite | Level 9

Thank you So much, Ballardw. 

            I have googled so much to get this, but your experience beats everything. Thanks again. You are great. 

buddha_d
Pyrite | Level 9
Please respond soon
data_null__
Jade | Level 19

You can use the PROC FORMAT and the PICTURE statement to make the format you desire.

buddha_d
Pyrite | Level 9

Thanks data _null_ it works

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 1579 views
  • 2 likes
  • 3 in conversation