Hello SAS Community, I've been working on a project that queries data each quarter and I wanted to create a macro that will make a column with the current federal quarter and fiscal year column. Essentially this: So I started by making macros. At the time of creating them, they were resolving and the columns were created in my dataset. However, I was puzzled to find that I received this warning/error from SAS when revisiting my program this morning: Here is the code I used to create the macros: /* Create quarter and fiscal year macro variable.*/
%macro GetQuarterFromDate();;
%let date = %sysfunc(today()); /* Get today's date */
%let quarter = 0;
%let month = %sysfunc(month(&date));
%if &month <= 3 %then %let quarter = 3;
%else %if &month <= 6 %then %let quarter = 4;
%else %if &month <= 9 %then %let quarter = 1;
%else %if &month <= 12 %then %let quarter = 2;
%put Quarter &quarter;
%mend;
%GetQuarterFromDate();
%macro GetFiscalYearFromDate();
%let date = %sysfunc(today()); /* Get today's date */
%let startYear = %eval(%sysfunc(year(&date)) - (%sysfunc(month(&date)) <= 6));
%let endYear = %eval(&startYear + 1);
%let fiscalYear = FY &startYear.-&endYear.;
%put &fiscalYear;
%mend;
%GetFiscalYearFromDate(); Here is the code I used when creating a column with the macro as its value in a dataset. I swapped out my original dataset to SASHELP.stocks, if you want to test: data quar_fisc;
set sashelp.stocks;
%GetQuarterFromDate;
QuarterColumn = catx(' ', "Quarter", &quarter); /* Concatenate text with quarter value */
%GetFiscalYearFromDate;
FiscalYearColumn = "&fiscalYear";
run;
data final;
set quar_fisc;
CombinedColumn = catx(', ', QuarterColumn, FiscalYearColumn);
drop QuarterColumn FiscalYearColumn;
run; Any help is much appreciated!
... View more