DATA Step, Macro, Functions and more

Date time informat that works when the date time lengths are different

Reply
Super Contributor
Posts: 324

Date time informat that works when the date time lengths are different

Dear,

 

For the following variable 'a', I need to use two informats to get the output I need. Is there any other format that can both OBS.

 

output needed;

01SEP17:15:10:00

04SEP17:00:00:00

 

Thank you.

data one;
input a $16.;
datalines;
2017-09-01T15:10
2017-09-04
;
data two;
set one;
b=input(a, anydtdtm.);
c=input(a,?? is8601dt.);
format b c datetime16.;
run;
Super User
Super User
Posts: 9,813

Re: Date time informat that works when the date time lengths are different

Posted in reply to knveraraju91

Well, a simple conditional:

data one;
  input a $16.;
datalines;
2017-09-01T15:10
2017-09-04
;
run;

data two;
  set one;
  b=ifn(lengthn(a)=10,input(catx('T',a,"00:00"),e8601dt.),input(a,e8601dt.));
  format b datetime.;
run;

Its more or less the same thing however.  

Ask a Question
Discussion stats
  • 1 reply
  • 96 views
  • 1 like
  • 2 in conversation