BookmarkSubscribeRSS Feed
PatrykSAS
Obsidian | Level 7

Hello,

I have variable with date and hour, what I'd like to do is to create a timestamp. For example:

DATE HOUR
2021-06-22 13

I wish I could get 2021-06-22 13:00:00

How can I solve that?

2 REPLIES 2
NicoM
Obsidian | Level 7

Indeed you can do this using the DHMS function. Assuming your variable DATE is a SAS date and HOUR is numeric you would get something like this.

 

data want; 
	date = '22jun2021'd; 
	hour = 13; 

	timestamp = dhms(date, hour, 0, 0);

	format date date9. timestamp datetime22.; 
run;

In case your DATE variable is character, you would need to do some pre-processing to get to the timestamp.

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 2 replies
  • 1356 views
  • 1 like
  • 3 in conversation