BookmarkSubscribeRSS Feed
nickspencer
Obsidian | Level 7

Is there any SAS date format that displays the current month and year in full?

 

For example, the current value should be April 2020

 

4 REPLIES 4
nickspencer
Obsidian | Level 7

I tried worddate. format but it gives me day as well which I don't need.

 

data test1;
a=put(today(),worddate.);
run;

 

output:     April 28, 2020

 

I need : April 2020

Astounding
PROC Star

I don't know of a format that gives you exactly what you want.  But if you start with WORDDATX instead of WORDDATE, it will be easier to extract the pieces you want.

ballardw
Super User

Proc Format will allow you to make a large number of custom formats using the Picture with directives and indicating that the data is expected to be a date, time or datetime value.

proc format ;
picture mymonthyear (default=15)
low-high = '%B %Y' (datatype=date)
;
run;

data example;
   do month=1 to 12;
      date = mdy(month,1,2020);
      put 'Date is ' date mymonthyear.;
   end;
run;

The default= is to determine the default number of characters to display. If not included the formats tend to be 8 characters and a tad short. Depending on exact desired use you may need to use the -L (left justify) with Put.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2905 views
  • 2 likes
  • 4 in conversation