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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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