To format a date variable with a month and year format in SAS, you can use the monyy5. or monyy7. date formats.
data example;
d = "15sep2022"d;
put d monyy5.;
put d monyy7.;
run;
// Log Output:
SEP22
SEP2022
When working with different variables in SAS, the ability to change formats easily is valuable.
One such case is if you have a date and want to format it differently.
A common date format which is commonly used in real world applications is showing the month and year of a date.
To format a date like month and year in SAS, you can use the monyyw. date format. The two valid formats for month and year are the monyy5. or monyy7. date formats.
Below shows you how to format a date with the monyy5. or monyy7. date formats in SAS.
data example;
d = "15sep2022"d;
put d monyy5.;
put d monyy7.;
run;
// Log Output:
SEP22
SEP2022
Hopefully this article has been useful for you to learn how to use the month year format MONYYw. in a SAS data step.