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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3162 views
  • 3 likes
  • 4 in conversation