Hello mentors,
I have a macro variable 'test' such that when I check its value, it says unresolved macro:
%put &=test ;
WARNING: Apparent symbolic reference TEST not resolved.
test
I then have a code to check if the macro variable is empty or not, if empty I need to give it a default value (with the quotes) ‘cycle=0’, and I've seen snippets of this code a couple of times in these forums
%macro isBlank(param);
%sysevalf(%superq(param)=,boolean)
%mend isBlank;
%macro runStuff;
%if %isblank(&test.) = 1 %then %do;
%put blank;
call symput('test',"'cycle = 0'");
%end;
%else %do;
%put notblank;
%end;
%mend runStuff;
%runStuff;
%put &=test ;
But for some reason, the output value from the boolean expression is '0' instead of the expected '1'. Why would that happen when the macro is unresolved?
Log below for reference, appreciate the help in helping me understand this concept.
Log:
25 GOPTIONS ACCESSIBLE;
26 %macro isBlank(param);
27 %sysevalf(%superq(param)=,boolean)
28 %mend isBlank;
29
30 %macro runStuff;
31 %if %isblank(&test.) = 1 %then %do;
32 %put blank;
33 call symput('test',"'cycle = 0'");
34 %end;
35 %else %do;
36 %put notblank;
37 %end;
38
39 %mend runStuff;
40 %runStuff;
MLOGIC(RUNSTUFF): Beginning execution.
MLOGIC(ISBLANK): Beginning execution.
WARNING: Apparent symbolic reference TEST not resolved.
MLOGIC(ISBLANK): Parameter PARAM has value &test.
MLOGIC(ISBLANK): Ending execution.
MLOGIC(RUNSTUFF): %IF condition %isblank(&test.) = 1 is FALSE
MLOGIC(RUNSTUFF): %PUT notblank
notblank
MLOGIC(RUNSTUFF): Ending execution.
41
42 %put &=test ;
WARNING: Apparent symbolic reference TEST not resolved.
test
The CALL SYMPUT routine can only be used in a DATA step. You are trying to use it in open code. Also you can't check to see if a macro variable contains a blank value if it isn't yet defined. Try this:
%macro runStuff;
%let test = ;
%if %isblank(&test.) = 1 %then %do;
%put blank;
%let test = 'cycle = 0';
%end;
%else %do;
%put notblank;
%end;
%mend runStuff;
@AJ_Brien wrote:
Thank you for your response.
The macro variable test gets created and assigned a value in a seperate unrelated query. However, in some scenarios, it does get created but there is no value assigned to it. Therefore, I used %put &=test ; statement before running the above code and got the following warning
WARNING: Apparent symbolic reference TEST not resolved.
test
The issue for me is that even though 'test' does not have a value assigned, when I run the above code, the boolean output is 0 instead of the expected value of 1.
There is a function to check if a macro variable exists.
%put %symexist(TEST);
If the underlying problem is caused by using the INTO clause of PROC SQL to populate the macro variable then set the default value before the query that you are using to set it.
%let test=0;
select count(*) format=32. into :test trimmed
from sashelp.class where sex='UNKNOWN'
;
Then your later steps can be assured the macro variable will have a value whether or not any observations are found by the query.
That doesn't make any sense as a way to check the value of a macro variable. Your condition is not going to be changed by the value of the macro variable TEST. A single quote character is never going to be the same as a double quote character so it is always going to be false.
Please clarify what you are actually trying to test.
Do you want to check if the macro variable exists?
%symexist(TEST)
Do you want to check if it has any value?
%length(%superq(test))
Do you want to check if it has a value that is not just spaces?
%sysevalf(%superq(test)=,boolean)
https://support.sas.com/resources/papers/proceedings09/022-2009.pdf
@AJ_Brien - In that case you haven't posted the whole problem. Where do you define TEST - if it is inside another macro for example then it will only resolve in that macro and not outside it hence your warning message. If you want TEST to resolve everywhere then define it in a %GLOBAL statement - %global test; - at the start of your program.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.