Hello
In my data set there are 2 columns: date and time.
In order to calculate column date_time I am using the following code:
dhms(date, 0, 0, time )as date_time
However,In some rows I get bad results and the date_time field has no correct value,
Date column with informat date9. and format date9.
Time column with format time5. and informat is null
Hi,
I'd say check your data, your SQL and your Log.
data demo;
date = '08SEP2022'd;
time = '12:57't;
date_time = dhms(date, 0, 0, time);
format date_time datetime20. date date9. time time5.;
run;
proc print data=demo;
run;
- Cheers -
What exactly is the value of "bad results"?
I think your code will give you the datetime value without any problem.
data have;
date='08sep2022'd;time='12:57't;output;
date='14sep2022'd;time='8:15't;output;
format date date9. time time5. ;
run;
data want;
set have;
date_time =dhms(date, 0, 0, time );
format date_time datetime16.;
run;
proc print;run;
proc sql;
select have.*, dhms(date, 0, 0, time )as date_time format=datetime16. from have;
quit;
Please look at this row of data.
Here the result that I get is wrong
Hi,
I'd say check your data, your SQL and your Log.
data demo;
date = '08SEP2022'd;
time = '12:57't;
date_time = dhms(date, 0, 0, time);
format date_time datetime20. date date9. time time5.;
run;
proc print data=demo;
run;
- Cheers -
Your posted code looks good to me.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.