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)');
%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)');
I tried that first, but it still did not resolve.
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.