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

Hi All!

 

May I have suggestions on how to format a SAS date to this  12-05-2018 15:56.  I need dashes not slashes 🙂 THANKS! 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

https://communities.sas.com/t5/New-SAS-User/FileName-with-Date-and-Time/m-p/578096/highlight/true#M1...

 

proc format; 
  picture  datetimeStamp
          low-high='%Y-%0m-%0d %0H:%0M' (datatype=datetime);
run;

%put %sysfunc(datetime(), datetimeStamp.);

documentation reference:

https://documentation.sas.com/?docsetId=proc&docsetTarget=p0n990vq8gxca6n1vnsracr6jp2c.htm&docsetVer...

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

To make a DATE look xx-xx-xxxx use either MMDDYYD or DDMMYYD format, depending on whether your example was supposed to represent the Dec 5th or 12th of May.

 

Why does you example include a time part?  Do you want to make a DATETIME value instead of DATE value?

NJGIRL
Obsidian | Level 7
correct. It needs to be a datetime.
thanks!
Reeza
Super User
I don't believe there's a default format that does this. But if you check the posts from the last month that revolve around date or datetime I'm about 99% certain this exact question was asked and answered about 3 times in the past few weeks.
NJGIRL
Obsidian | Level 7
Yes, that's the issue: I can not find a default datetime format to accomplish this. I did look in recent posts but I can not find another similar, however, I will search again. Do you happen to remember the tittle of the post as I have seen several date/time issues discussed  but none that specifically address formatting with slashes (and include time).
I do have  solution in mind but curious to see if there was some other creative ideas! thanks, take care! 
Reeza
Super User

https://communities.sas.com/t5/New-SAS-User/FileName-with-Date-and-Time/m-p/578096/highlight/true#M1...

 

proc format; 
  picture  datetimeStamp
          low-high='%Y-%0m-%0d %0H:%0M' (datatype=datetime);
run;

%put %sysfunc(datetime(), datetimeStamp.);

documentation reference:

https://documentation.sas.com/?docsetId=proc&docsetTarget=p0n990vq8gxca6n1vnsracr6jp2c.htm&docsetVer...

NJGIRL
Obsidian | Level 7
super cool! thanks! 
Tom
Super User Tom
Super User

You could keep the values as DATETIME and make user defined picture format to display it the way you want.

Or you could create a character variable that displays the value the way you want.

length char_var $16;
char_var=catx(' ',put(datepart(datetime_var),mmddyyd10.),put(timepart(datetime_var),tod5.));

 

But you probably do NOT want to use MM-DD-YYYY (or DD-MM-YYY either) to display your datetime values. Which ever one you pick will confuse half of the people reading the reports. Plus the character string version will not sort in chronological order.

 

Use YYYY-MM-DD instead.

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