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?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.