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?
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.