BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
deengyn
Obsidian | Level 7

Hi all, 

I currently have the date (varname: serv_date) presented in the format of  (DDMMMYYYY HH:MM:SS). Currently, I'm trying to reformat it so that the table would only contain ddmmmyyyy.

I've tried some solutions such as ...

proc sql; 
create table test as 
select serv_date format = date9.
from plastics_fnl; 
quit;

But the output is quite odd and unexpected. 

Date issues.PNG

 

May someone help identify a solution as well as explain what went wrong in the code I provided?

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

How about 

proc sql; 
create table test as 
select datepart(serv_date) as serv_date format = date9.
from plastics_fnl; 
quit;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

How about 

proc sql; 
create table test as 
select datepart(serv_date) as serv_date format = date9.
from plastics_fnl; 
quit;
deengyn
Obsidian | Level 7
Amazing! Thank you for the quick response and help!
ballardw
Super User

If a value is a SAS datetime value then the units are SECONDS, if a date then the units are DAYS. So you cannot use a date9 format to display datetime. If you assign a datetime9. format then that will appear similar to a date9 format.

 

OR use the datepart(dtvariable) function to create date value.

 

PaigeMiller
Diamond | Level 26

You don't need to create a new date variable. All you need to do is assign the DTDATE format.

https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=leforinforref&docsetTarget=n1...

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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