DATA Step, Macro, Functions and more

conver char date to format date

Accepted Solution Solved
Reply
Contributor
Posts: 67
Accepted Solution

conver char date to format date

my table date as date in format 10JUN2018:10:08:40.216 expecting 06-10-2018.

 

Thank you


Accepted Solutions
Solution
Tuesday
PROC Star
Posts: 1,566

Re: conver char date to format date

[ Edited ]
Posted in reply to novinosrin
data w;
date='10JUN2018:10:08:40.216';
new_date=datepart(input(date, datetime20.));
format new_date mmddyyd10.;
run;

 

Applying this for '-'

 

mmddyyd10

 

View solution in original post


All Replies
PROC Star
Posts: 1,566

Re: conver char date to format date

data w;
date='10JUN2018:10:08:40.216';
new_date=datepart(input(date, datetime20.));
format new_date mmddyy10.;
run;
Solution
Tuesday
PROC Star
Posts: 1,566

Re: conver char date to format date

[ Edited ]
Posted in reply to novinosrin
data w;
date='10JUN2018:10:08:40.216';
new_date=datepart(input(date, datetime20.));
format new_date mmddyyd10.;
run;

 

Applying this for '-'

 

mmddyyd10

 

Super User
Posts: 13,299

Re: conver char date to format date

Posted in reply to novinosrin

Or if the existing variable is consistent you can read with the DATE9. informat:

data example;
   date='10JUN2018:10:08:40.216';
   newdate= input(date,date9.);
   format newdate mmddyyd10.;
run;

The informat will only read the first 9 characters.

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 78 views
  • 0 likes
  • 3 in conversation