BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to create a new column called SAS_date_time with format of date time.

What is the way to combine the date+time fields together?

Data have ;
format SAS_date date9.;
input SAS_date : date9. num_time;
cards;
'19JAN2021'd 101602
'13AUG2020'd 164500
;
Run;

Data have2;
SET have;
string1 = put(num_time,z6.);
string2 = catx(":",substr(string1,1,2),substr(string1,3,2),substr(string1,5,2));
SAS_time = input(string2,time8.);
format SAS_time time8.;
KEEP  SAS_date  SAS_time;
Run;
2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

No need to do all those character functions 🙂

 

Data have ;
format SAS_date date9.;
input SAS_date : date9. num_time;
cards;
'19JAN2021'd 101602
'13AUG2020'd 164500
;
Run;

data want;
   set have;
   dt = dhms(SAS_date, 0, 0, input(put(num_time, 6.), hhmmss6.));
   format dt datetime20.;
run;
s_lassen
Meteorite | Level 14

With the data you have, you can go directly from the variables you start with to the datetime value, using PUT and INPUT:

sas_datetime=input(put(sas_date,yymmddn8.)||'T'||put(num_time,z6.),B8601DT.);

There are many datetime informats, you can almost always find one that fits your needs.

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