How to convert the following Charater to Date format?
For example, raw variable DATE "01 MAR 2013 00:00:02.358". The length is 24. There are space between '01' and 'MAR' and '2013' and '00'.
How to seperate it into two column '03/01/2013' + 'hh:mm:ss:sss' or 'hh:mm:ss'. Both are date format. Thanks!
Hi ZZB;
try this
data have;
DATE = "01 MAR 2013 00:00:02.358";
run;
data want;
set have;
NewDate = input(compress (substr(DATE ,1,11)),date9.);
NewTime = input( scan(DATE,-1,' '),time12.);
format NewDate date9. NewTime time12.;
run;
Are you reading these from a text file or is the data already in SAS?
You can try compress and input to read in the data.
untested:
datetimevar=input(compress(char_val), anydtdtm.);
var_datepart=datepart(datetimevar);
var_timepart=timepart(datetimevar);
format var_datepart date9. var_timepart time8.;
The informat provided by @data_null__ is the correct informat. Correcting the informat fixes the issues.
data have;
original_var = "01 MAR 2013 00:00:02.358";
temp=compress(original_var);
dt_var=input(original_var, datetime24.3);
date_part=datepart(dt_var);
time_part=timepart(dt_var);
format dt_var datetime24.3 date_part date9. time_part time11.3;
run;
proc print data=have;
run;
34 data _null_;
35 input dt & datetime.;
36 put (dt)(=datetime22.3);
37 list;
38 cards;
dt=01MAR2013:00:00:02.358
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
39 01 MAR 2013 00:00:02.358
Hi ZZB;
try this
data have;
DATE = "01 MAR 2013 00:00:02.358";
run;
data want;
set have;
NewDate = input(compress (substr(DATE ,1,11)),date9.);
NewTime = input( scan(DATE,-1,' '),time12.);
format NewDate date9. NewTime time12.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.