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

Hi there,

 

I get an issue on macrovariable.inside another one.

I explain:

 

I call a macro function A like this:

%A (mymacrovariable = MMV);
%put &MMV.;

 

My macro function A is something like this:

%macro A (mymacrovariable);

%global &mymacrovariable.;
&&mymacrovariable. = 0;

%mend;

When I run it I have an issue on MMV...

MLOGIC(A):  Beginning execution.
MLOGIC(A):  Parameter MYMACROVARIABLE has value MMV
MLOGIC(A):  %GLOBAL  &MYMACROVARIABLE.
MPRINT(A):   MMV = 0;

MLOGIC(A):  Ending execution.
NOTE: Line generated by the macro variable "MYMACROVARIABLE".
31           MMV
             ___
             180
ERROR 180-322: Statement is not valid or it is used out of proper order.

32         %put &MMV.;
 
33         
34         GOPTIONS NOACCESSIBLE;
35         %LET _CLIENTTASKLABEL=;
36         %LET _CLIENTPROCESSFLOWNAME=;
37         %LET _CLIENTPROJECTPATH=;
38         %LET _CLIENTPROJECTNAME=;
39         %LET _SASPROGRAMFILE=;
40         
41         ;*';*";*/;quit;run;
42         ODS _ALL_ CLOSE;
43         
44         
2                                                          The SAS System                           11:18 Thursday, October 19, 2017

45         QUIT; RUN;
46         

Can you help me to solve it?

 

Thanks,

FP12

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

%macro A (mymacrovariable);

	%global &mymacrovariable.;
	%let &mymacrovariable.=0;

%mend;

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This:

&&mymacrovariable. = 0;

Generates a Base SAS statement:

mmv= 0;

 Which is not in a datastep, thus error.

 

But seriously, why? You are hitting every bad programming practice there, creating global variables in macros, passing references to macro variables etc.  There is never a need to goto this level.  Base SAS is the programming language, Macro is an additional component - never needed - to help create generic code.  All it does is create some text, nothing more, it is not a replacement for Base SAS.  As simple example, if you find you passing data across multiple items, just put them in a dataset and use simple datastep to process things.  You will find your code becomes simpler, and more robust.

FP12
Obsidian | Level 7

Thanks for the answer.

But seriously, why?

 

I didn't want to write the complete code here. It is just the part of the code interesting here. There are also other parameters inside the macro function. The variable won't be always 0.

 

Moreover I create some other variables using the same macro function (and using different values for parameters of the macro function).

Instead of writing several time the same datastep for several macrovariables, it is much readable and better practises to write the code only once, I am sure 🙂

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Without seeing the code I can't say specifically, however I would almost never see a need for multiple macro variables, references to them being passed into macro functions, and global macro variables being created within separate macro functions.  You will get problems later on.  A good tip is to write the code once as Base SAS, then if there are some repetitons, extract that part of the code and create macros from it.  Essentially, what you are doing with macro is writing Base SAS code, but just doing it in a very complicated way.  

gamotte
Rhodochrosite | Level 12

Hello,

 

%macro A (mymacrovariable);

	%global &mymacrovariable.;
	%let &mymacrovariable.=0;

%mend;
FP12
Obsidian | Level 7

Thanks, it worked. 🙂

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
  • 5 replies
  • 1076 views
  • 2 likes
  • 3 in conversation