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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 1138 views
  • 3 likes
  • 3 in conversation