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?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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