SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
DonnieJ
Obsidian | Level 7

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)');
3 REPLIES 3
JeffMeyers
Barite | Level 11

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');

 

ChrisNZ
Tourmaline | Level 20

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;

 

Rikard
Fluorite | Level 6

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

 

CHANGE

%GLOBAL &IVINC; 

 TO

%GLOBAL IVINC; 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 2047 views
  • 0 likes
  • 4 in conversation