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

A quick question.

How do I convert this $21 to DATETIME18.?

I have this: 2014-04-17 06:18:24

I want this: 17APR14:06:18:24

What's wrong with my code?

timestamp1=input(timestamp,datetime18.);

format timestamp1 datetime18.;

Thank you! Smiley Happy

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Sorry, it should have been informat ANYDTDTM21. - PG

PG

View solution in original post

7 REPLIES 7
PGStats
Opal | Level 21

Try

timestamp1=input(timestamp, anydtdte21.);

format timestamp1 datetime18.;

PG

PG
shixin
Calcite | Level 5

2014-04-09 06:24:28    became    01JAN60:05:30:22


The format is correct but it's the wrong date and time, hmm.. 

PGStats
Opal | Level 21

Sorry, it should have been informat ANYDTDTM21. - PG

PG
shixin
Calcite | Level 5

why when I run a case when statement on my newly formatted datetime, it says:

case when dt=MIN(dt) then ....

ERROR: Result of WHEN clause 2 is not the same data type as the preceding

       results.

ERROR: Expression using not equals (^=) has components that are of different

       data types.

Qn: Shouldn't the format of MIN(dt) be the same as dt???

Haikuo
Onyx | Level 15

Strongly suspect 'dt' is Char.

PGStats
Opal | Level 21

Please show the whole case ... end code block.

PG
JasonAllen
SAS Employee

Hello shixin,

Maybe try:

data _null_;

  string='2014-04-17 06:18:24';

  date=input(scan(string,1,' '),E8601DA10.);

  put date= date.;

  time=input(scan(string,2,' '),time.);

  put time= time.;

  dt=dhms(date,0,0,time);

  put dt datetime.;

run;

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