DATA Step, Macro, Functions and more

Datetime format

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

Datetime format

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

Accepted Solutions
Solution
‎07-13-2017 06:35 PM
Super User
Posts: 10,500

Re: Datetime format

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


All Replies
Respected Advisor
Posts: 3,777

Re: Datetime format

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
Contributor
Posts: 71

Re: Datetime format

Input should be 12JUN16:16:30:55 and output should look like 06/12/2016 4:30:55 PM
Solution
‎07-13-2017 06:35 PM
Super User
Posts: 10,500

Re: Datetime format

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;
Contributor
Posts: 71

Re: Datetime format

Thank you So much, Ballardw. 

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

Contributor
Posts: 71

Re: Datetime format

Please respond soon
Respected Advisor
Posts: 3,777

Re: Datetime format

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

Contributor
Posts: 71

Re: Datetime format

Thanks data _null_ it works

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 195 views
  • 2 likes
  • 3 in conversation