I want to create a SAS macro that creates symbols for this year and last year and last month's month number. So far I have:
%let LastMonth = %sysfunc(intnx(month,%sysfunc(date()),-1),DATE9.);
%let ThisMonth = %sysfunc(intnx(month,%sysfunc(date()),0),DATE9.);
%let ThisYear = %sysfunc(intnx(year,%sysfunc(date()),0),DATE9.);
%let LastYear = %sysfunc(intnx(year,%sysfunc(date()),-1),DATE9.);
These give: %put &LastYear; -> 01JAN2013 %put &ThisYear; -> 01JAN2014 %put &LastMonth; -> 01JAN2014 %put &ThisMonth; -> 01FEB2014
I am having trouble extracting the year and month numbers so that &LastMonth I'd like to get 1 (For January) and &Last year 2013 etc.
For the months I tried using the month() function:
%let LastMonth = %sysfunc(month(%sysfunc(intnx(month,%sysfunc(date()),-1),DATE9.)));
but this gives an error and I don't understand why it occurs as :
ERROR: Argument 1 to function MONTH referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or
%QSYSFUNC function reference is terminated.
Any help appreciated!
date9.
format you are applying during macro assignment for last year & month. – user1509107