BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

In my data set there are 2 columns:  date  and time.

Ronein_4-1663227166033.png

Ronein_0-1663228392211.png

 

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.

Ronein_3-1663227113659.png

 

Time column with format time5.  and informat is null

Ronein_2-1663227075914.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

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 -

View solution in original post

5 REPLIES 5
japelin
Rhodochrosite | Level 12

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;

japelin_0-1663227990848.png

 

Ronein
Meteorite | Level 14

Please look at this row of data.

Here the result that I get is wrong

Ronein_0-1663228337249.png

 

japelin
Rhodochrosite | Level 12
Can the code for the entire step, not just the dhms function part, be timed as much as possible?
Oligolas
Barite | Level 11

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 -

PeterClemmensen
Tourmaline | Level 20

Your posted code looks good to me.

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1038 views
  • 1 like
  • 4 in conversation