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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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