BookmarkSubscribeRSS Feed
radhikaa4
Calcite | Level 5

Current table

subjectidstart datestarttime
123-Nov-191213
224-Nov-191914

Need to combine date and time into one

 

subjectidstart datestarttimestart_date_time
123-Nov-19121311/23/19 12:13
224-Nov-19191411/24/19 19:14

 

I tried to concatenate but it is not a good approach

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please tell us if the variable start_date is a numeric or character variable.

 

Please tell us if the variable starttime is a numeric or character variable.

--
Paige Miller
radhikaa4
Calcite | Level 5
Start date is date9. And time is 50 character


PaigeMiller
Diamond | Level 26

So date is numeric, while time is character? So you would have to convert the character string time into hours and minutes as numbers, which is what this code does.

 

data want;
     set have;
     datetime=dhms(start_date,input(substr(time,1,2),2.),input(substr(time,3,2),2.),0);
     format datetime datetime16.;
run;

 

--
Paige Miller

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
  • 3 replies
  • 342 views
  • 0 likes
  • 2 in conversation