DATA Step, Macro, Functions and more

Global Variable not Resolving in Macro

Reply
Contributor
Posts: 20

Global Variable not Resolving in Macro

[ Edited ]

I have a global variable created by a SELECT :INTO and it was resolving when I was NOT using a macro. Now I need to bound a large part of my code inside a macro because I need to conditionally CALL EXECUTE this macro as a means to bypass or run the code. Below is a simplified version of what I am trying to do. The global variable &IVINC is not resolving. Thanks for the help!

%MACRO FCST_CHK1(IVINC);
%GLOBAL &IVINC;  

PROC SQL;
SELECT COUNT(VIN17) INTO :IVINC FROM INCV; DATA _NULL_; /* TEST IF INCENTIVE FILE IS EMPTY */ IF &IVINC = 0 THEN DO; FILE RETURNC; PUT @01 'RETURN CODE 01: THE INCENTIVE FILE IS EMPTY'; ABORT RETURN 01; END; %MEND(FCST_CHK1); DATA _NULL_; IF "&FCST_Y" = '0' THEN CALL EXECUTE('%FCST_CHK1(&IVINC)');
Contributor
Posts: 35

Re: Global Variable not Resolving in Macro

Hello,

   Two things:

1) A macro variable won't resolve unless it's within double quotes I believe.

2) From what I can see is that you're trying to call the macro that makes the macro variable by using the macro variable that you haven't made yet.  Your Call Execute function

CALL EXECUTE('%FCST_CHK1(&IVINC)');  

 uses the &ivinc macro variable that is created by your %fcst_chk1 macro. 

 

Maybe you're trying to do the following instead?  You don't have to have parameters to run a macro.

%MACRO FCST_CHK1;
%GLOBAL &IVINC;  

PROC SQL;	SELECT COUNT(VIN17)
	INTO :IVINC
	FROM INCV;
	
DATA _NULL_; /* TEST IF INCENTIVE FILE IS EMPTY */
	IF &IVINC = 0 THEN DO;
		FILE RETURNC;
		PUT	@01	'RETURN CODE 01: THE INCENTIVE FILE IS EMPTY';
		ABORT RETURN 01;
	END;

%MEND(FCST_CHK1);

DATA _NULL_;
	IF "&FCST_Y" = '0' THEN CALL EXECUTE('%FCST_CHK1');

 

Super User
Posts: 2,518

Re: Global Variable not Resolving in Macro

[ Edited ]

Not too sure I understood your exact goal, but this works:

%macro fcst_chk1(ivinc);
  %global &ivinc;  

  proc sql noprint; select count(*) into :&ivinc trimmed from SASHELP.CLASS; quit;

  data _null_; if symget("&IVINC") = '0' then putlog 'a'; run;

%mend;
%let ivinc=aa;
data _null_;         
  if 1 then call execute('%fcst_chk1(&ivinc)');
run;

 

Occasional Contributor
Posts: 8

Re: Global Variable not Resolving in Macro

You probably whant to made the macro variable INVIC global, i.e.:

 

CHANGE

%GLOBAL &IVINC; 

 TO

%GLOBAL IVINC; 
Ask a Question
Discussion stats
  • 3 replies
  • 100 views
  • 0 likes
  • 4 in conversation