How can I save the marked line as a macro variable containing text like 06?
PROC FORMAT;
value Fiscal_Period_Format
1='07'
2='08'
3='09'
4='10'
5='11'
6='12'
7='01'
8='02'
9='03'
10='04'
11='05'
12='06';
RUN;
%macro setDates();
%let currentFiscalPeriod = input(month(date()), Fiscal_Period_Format.); /*this line blows up*/
%put ¤tFiscalPeriod;
%mend;
%setDates();
You need some %sysfunc() functions in order to do some of those functions as they are not macro functions. Try the following:
proc format;
value fiscal_period_format
1='07'
2='08'
3='09'
4='10'
5='11'
6='12'
7='01'
8='02'
9='03'
10='04'
11='05'
12='06';
run;
%macro setDates;
%let currFiscalPd=%sysfunc(month(%sysfunc(date())),fiscal_period_format.);
%put &currFiscalPd;
%mend;
%setDates;
You need some %sysfunc() functions in order to do some of those functions as they are not macro functions. Try the following:
proc format;
value fiscal_period_format
1='07'
2='08'
3='09'
4='10'
5='11'
6='12'
7='01'
8='02'
9='03'
10='04'
11='05'
12='06';
run;
%macro setDates;
%let currFiscalPd=%sysfunc(month(%sysfunc(date())),fiscal_period_format.);
%put &currFiscalPd;
%mend;
%setDates;
This program has several issues (don't we all?), but all can be fixed.
%SYSFUNC is required to allow macro language to execute a DATA step function. Unfortunately, that clutters the program significantly. Try it this way:
%let currentFiscalPeriod = %sysfunc(putn(%sysfunc(month(%sysfunc(date()))), Fiscal_Period_Format.));
If this gives you any trouble, try removing the dot from the format name: ... Fiscal_Period_Format));
Good luck.
My question would be, why do you need to do this in macro language? There doesn't seem to be any value, and simple Base SAS would do this just fine:
data _null_; call symput('currentFiscalPeriod',input(month(date()),fiscal_period_format.); run;
Saying that, not sure why you need the format either, why does z2. not suffice?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.