BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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;
1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 721 views
  • 1 like
  • 2 in conversation