BookmarkSubscribeRSS Feed
DonnieJ
Obsidian | Level 7

I am generating a Global variable using a SELECT :INTO and it was resolving before using a macro. Now I need to bound a large part of my code inside a macro and use a conditional CALL EXECUTE as a means to bypass or run my code. Now that I am generating this variable inside the macro, it is not resolving. Below is a simplified version of the code. Thanks for the help!

%MACRO FCST_CHK1(IVINC);
%GLOBAL &IVINC; /* INCENTIVE FILE VIN COUNT */

PROC SQL; /* CREATE VIN COUNT FOR INCENTIVE FILE TEST */
	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)');

 

 

4 REPLIES 4
Reeza
Super User
%GLOBAL IVINC; 

I don't think you need the ampersand, otherwise it resolves to whatever value &ivinc has so you're setting the wrong thing to be global.

 


@DonnieJ wrote:

I am generating a Global variable using a SELECT :INTO and it was resolving before using a macro. Now I need to bound a large part of my code inside a macro and use a conditional CALL EXECUTE as a means to bypass or run my code. Now that I am generating this variable inside the macro, it is not resolving. Below is a simplified version of the code. Thanks for the help!

%MACRO FCST_CHK1(IVINC);
%GLOBAL &IVINC; /* INCENTIVE FILE VIN COUNT */

PROC SQL; /* CREATE VIN COUNT FOR INCENTIVE FILE TEST */
	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)');

 

 



 

DonnieJ
Obsidian | Level 7

I tried that first, but it still did not resolve.

Reeza
Super User
Macro variables do not resolve in single quotes. I can't run your code to test it ... so showing what errors you're getting or 'not resolving' would help a lot here.
Astounding
PROC Star

This combination just by itself would create an error:

 

%macro FCST_CHK1 (IVINC);

   %global IVINC;

 

Your macro has a local macro variable named IVINC.  You cannot move it to the global table by using a %GLOBAL statement.  In fact, SAS will assume that's what you want to do, will not allow it, and will give you an error message so that you don't think that this actually worked.  You would see that if  you were to try:

 

%macro FCST_CHK1(IVINC);

   %global IVINC;

 

You can easily get around the problem by letting SQL populate the local variable (into : ivinc), and copying the result to a global variable.  For example:

 

%global new_name;

 

Then after the PROC SQL:

 

%let new_name = &ivinc;

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
  • 4 replies
  • 696 views
  • 0 likes
  • 3 in conversation