Solved
Contributor
Posts: 22

# How to convert this date from string to date ?

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!

Accepted Solutions
Solution
‎06-20-2014 04:32 PM
Posts: 5,539

## Re: How to convert this date from string to date ?

Sorry, it should have been informat ANYDTDTM21. - PG

PG

All Replies
Posts: 5,539

## Re: How to convert this date from string to date ?

Try

timestamp1=input(timestamp, anydtdte21.);

format timestamp1 datetime18.;

PG

PG
Contributor
Posts: 22

## Re: How to convert this date from string to date ?

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

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

Solution
‎06-20-2014 04:32 PM
Posts: 5,539

## Re: How to convert this date from string to date ?

Sorry, it should have been informat ANYDTDTM21. - PG

PG
Contributor
Posts: 22

## Re: How to convert this date from string to date ?

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???

Posts: 3,167

## Re: How to convert this date from string to date ?

Strongly suspect 'dt' is Char.

Posts: 5,539

## Re: How to convert this date from string to date ?

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

PG
SAS Employee
Posts: 15

## Re: How to convert this date from string to date ?

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;

🔒 This topic is solved and locked.