DATA Step, Macro, Functions and more

INPUT Statement

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

INPUT Statement

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!


Accepted Solutions
Solution
‎09-16-2014 09:07 AM
Trusted Advisor
Posts: 1,137

Re: INPUT Statement

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


All Replies
Solution
‎09-16-2014 09:07 AM
Trusted Advisor
Posts: 1,137

Re: INPUT Statement

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
Super User
Super User
Posts: 7,942

Re: INPUT Statement

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;

Contributor
Posts: 33

Re: INPUT Statement

Thanks guys!  Both very helpful answers.

Steve

🔒 This topic is solved and locked.

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

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