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