BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BU2B
Calcite | Level 5

Hey all,

I have a variable that's CHAR with length16 (2014-07-01 00:15).  I want to convert this to a DATETIME, so I tried the INPUT statement.

date = input(date1,datetime.);

Any help would be appreciated, thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

please try the informat anydtdtm20.

data have;

date1='2014-07-01 00:15';

date = input(date1,anydtdtm20.);

format date datetime20.;

run;

Thanks,

Jag

Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

please try the informat anydtdtm20.

data have;

date1='2014-07-01 00:15';

date = input(date1,anydtdtm20.);

format date datetime20.;

run;

Thanks,

Jag

Thanks,
Jag
RW9
Diamond | Level 26 RW9
Diamond | Level 26

There are various ways of doing it, mdy function etc.  Its more about selecting the appropriate formats for the data.  Below I show some which will get you the result (note you can combine the steps, have them here just as a descriptive).  Anyways, probably easiest is the anydtdtm informat.

data want;

  attrib a format=$16. b format=date9. c format=tod5. d format=datetime. e format=datetime.;

  a="2014-07-01 00:15";

  b=input(substr(a,1,10),yymmdd10.);

  c=input(substr(a,12,5),time5.);

  d=input(put(b,date9.)||":00"||put(c,tod5.),datetime.);

  e=input(a,anydtdtm.);

run;

BU2B
Calcite | Level 5

Thanks guys!  Both very helpful answers.

Steve

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1964 views
  • 3 likes
  • 3 in conversation