DATA Step, Macro, Functions and more

Datetime informat

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

Datetime informat

SAS community,
Input is like this
16JUN16:10:30:55 (properties: Length 8, Type Numeric, format datetime16.)


Output should look like
6/16/2016 10:30:55 AM (properties: length 22, Type character, don't know format & informants for this).

I tried proc format with picture (was suggested by ballardw, worked with windows sas, but this stupid saseg is giving error that it doesn't recognize anydtdtm. Informat).

SAS gurus please help.

Accepted Solutions
Solution
‎07-14-2017 01:57 PM
PROC Star
Posts: 7,363

Re: Datetime informat

Don't know why your code that runs in base wouldn't run in EG. However, the following should work in both:

 

data have;
  input dt datetime18.;
  format dt datetime18.;
  cards;
16JUN16:10:30:55
;

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

data want;
  set have;
  char_dt=put(dt,Exceldt.);
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎07-14-2017 01:57 PM
PROC Star
Posts: 7,363

Re: Datetime informat

Don't know why your code that runs in base wouldn't run in EG. However, the following should work in both:

 

data have;
  input dt datetime18.;
  format dt datetime18.;
  cards;
16JUN16:10:30:55
;

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

data want;
  set have;
  char_dt=put(dt,Exceldt.);
run;

Art, CEO, AnalystFinder.com

 

PROC Star
Posts: 252

Re: Datetime informat

this should do

proc format;

picture mydate other='%0m/%0d/%0Y %0H:%0M:%0S %p' (datatype=datetime);

run;

data a;

a= '16JUN16:10:30:55';

b= input(a, datetime.);

format b mydate.;

run;

 

Contributor
Posts: 71

Re: Datetime informat

Thanks Art, it worked finally. I appreciate your prompt response. Thank you
☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 110 views
  • 0 likes
  • 3 in conversation