How to convert string Date into SAS format date

date
sas
format
string

#1

I have variable Policy_Date in the data set and these values are not well formatted. Below is the snapshot of values.

Policy_Date
Aug 15 2014 10:23 AM
Sep 8 2011 11:34 AM
Aug 24 2003 18:23 PM
Mar 18 2010 07:12 AM

Guide me to convert these values to SAS standard format.

Regards,
Steve


#2

@Steve

You can use below code to perform this.Assume above date is stored in variable date of data set Test.

Data Check;
Set Test;
Mth=scan(date,1); /*Extracted Month Value*/
dy=scan(date,2); /*Extracted Day*/
Yr=Scan(date,3); /*Extracted Year*/
tm=Trim(Scan(date,4)); /*Extracted time*/
dte=Compress(Catx('',trim(dy),trim(Mth),trim(yr))); /*Date Formed as string*/
dtime=CAtx('',dte,tm); /*Date and time formed as string*/
Final=Input(dtime,date9.); /*Date formed as number*/
Run;

Regards,
Sunil