BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

 

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 &currentFiscalPeriod;

      %mend;
%setDates();

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
dcruik
Lapis Lazuli | Level 10

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;

View solution in original post

3 REPLIES 3
dcruik
Lapis Lazuli | Level 10

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;
Astounding
PROC Star

This program has several issues (don't we all?), but all can be fixed.

 

  1. Macro language does not execute DATA step functions.
  2. Even if you overcome issue #1, macro language would not execute PUT or INPUT functions.
  3. You are attempting to use INPUT with a format, when PUT would be the right tool.

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1604 views
  • 0 likes
  • 4 in conversation