user10745594
user10745594

Reputation:

How Do I Extract Just the Month and Year from a Full Date in SAS?

How do I extract just the Month and Year from a full SAS date. I know you can use the Year() and Month() functions, however, I would like to extract both at once.

Any suggestions?

For example my current date is 01/02/2018. I would like to create a new column with 02/2018.

Thanks!

Upvotes: 0

Views: 21331

Answers (2)

Tom
Tom

Reputation: 51611

SAS stores dates as the number of days since 1960, so a date value is a specific day. If you want all dates in the same month to appear the same then apply a date format that only displays the month and year (MONYYw., MMYYw., MMYYxw., etc.). If you want all dates in the same month to be transformed to the same date then use the INTNX() function. To transform DATE into MONTH_YEAR you could use this code.

month_year = intnx('month',date,0,'b');

And then attach your favorite format.

format month_year mmyys7. ;

Upvotes: 3

Gordon Linoff
Gordon Linoff

Reputation: 1270421

You can use the format in a proc sql statement. I think the format you want is::

proc sql;
    select datecol format = MMYYs7.

Upvotes: 1

Related Questions