BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
rykwong
Quartz | Level 8

Hi SAS community, I am trying to work with this variable (please see screenshot) which SAS is treating as a "datetime16."  I would like to create a separate date variable that has a format of "01JAN22" and a time variable of "07:26:27".  many thanks 

 

rykwong_0-1677092022109.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
dateVar = datepart(seriesTimeStamp);
format datevar date9.;
timeVar = timepart(seriesTimeStamp);
format timeVar time8.;

TIMEPART and DATEPART to extract the date/time components of a datetime variable. 

 

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You don't need a new variable for the date. Just assign the format DTDATE7. to this variable. If you want a time variable, use the TIMEPART function.

--
Paige Miller
Reeza
Super User
dateVar = datepart(seriesTimeStamp);
format datevar date9.;
timeVar = timepart(seriesTimeStamp);
format timeVar time8.;

TIMEPART and DATEPART to extract the date/time components of a datetime variable. 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3 replies
  • 1285 views
  • 4 likes
  • 3 in conversation