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

Let me start by saying the subject of the topic makes this seem simpler than it is.  I know how to get a month and year from a date already.  However, the month in this case appears as a number and I want the 3 letter abbreviation.  I tried using the monyy7. format, but using a format only changes the displayed value.  When I try to create another table in a PROC SQL statement to group by the new dates (MONTHYEAR) I get more than 1 row per month because the actual day is being read "behind the scenes".   How can I efficiently convert a date into the APR2022 value without using a format statement?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

So you want a new variable that contains the three letter month?

 

month_abbreviation = put(datevariable,monname3.);

 

While there are certainly good reasons to create this new variable, I point out that it will not sort in any meaningful order, this new variable will sort alphabetically so the first month of the year is APR and the second month of the year is AUG, and that's not usually what people want.

 

If you want the 3 letter abbreviation to appear and still have the months sort properly, then you would apply the format MONNAME3. to your date variable. 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

So you want a new variable that contains the three letter month?

 

month_abbreviation = put(datevariable,monname3.);

 

While there are certainly good reasons to create this new variable, I point out that it will not sort in any meaningful order, this new variable will sort alphabetically so the first month of the year is APR and the second month of the year is AUG, and that's not usually what people want.

 

If you want the 3 letter abbreviation to appear and still have the months sort properly, then you would apply the format MONNAME3. to your date variable. 

--
Paige Miller
RandoDando
Pyrite | Level 9
Thanks. That should get me where I want to go.

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
  • 2 replies
  • 2909 views
  • 0 likes
  • 2 in conversation