BookmarkSubscribeRSS Feed
angeliquec
Quartz | Level 8

Hi, I'd like to make a picture format of the date, but it should be in proper case. See samples below:

 

Date_Field       New_Date_Format

29MAR2020     29-Mar

01JAN2020       1-Jan

 

I'm exporting these to excel, so I prefer to maintain the date formats. Thanks.

3 REPLIES 3
Tom
Super User Tom
Super User
If you putting them into Excel then move the actual date and just tell Excel how you want it displayed.
Patrick
Opal | Level 21

If this is more about getting a specific format in Excel then below demonstrates how to use a style for defining such a format.

data have;
  input Date_Field:date9.;
  format Date_Field date9.;
  some_other_var1=_n_;
  some_other_var2='ABC';
  datalines;
29MAR2020
01JAN2020
;

options missing=' ';
ods listing close;
ods excel file='~/test/test.xlsx';
proc print data=have;
  var some_other_var1;
  var Date_Field / style(column)={tagattr='format: dd-mmm'};
  var some_other_var2;
run;
ods excel close;
ods listing;

 Patrick_0-1585464300513.png

 

ballardw
Super User

The SAS custom format would be:

Proc format library=work;
picture ddmon
low - high ='%d-%3B' (datatype=date);
;
run;

data example;
x = '29Mar2020'd;
y = '01Jan2020'd;
put x= ddmon. +1 y= ddmon.;
run;

Custom date formats like this may not work as intended when used with graphs though.

The quotes in the Picture statement must be single quotes and the case of the letters is important.

I have no idea if Excel will honor this either.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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