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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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