简体   繁体   中英

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!

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. ;

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

proc sql;
    select datecol format = MMYYs7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM