BookmarkSubscribeRSS Feed
AJ_Brien
Quartz | Level 8

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

 

7 REPLIES 7
SASKiwi
PROC Star

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
Quartz | Level 8
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.
Tom
Super User Tom
Super User

@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.

AJ_Brien
Quartz | Level 8
I tried the symexist too, it resolves to 1.

25 GOPTIONS ACCESSIBLE;
26 %global test;
27
28 %put &=test ;
SYMBOLGEN: Macro variable TEST resolves to
TEST=
29
30
31 %macro check;
32 %if %symexist(TEST)=0 %then %do;
33 %let test = 'cycle = 0';
34 %end;
35 %mend;
36 %check;
MLOGIC(CHECK): Beginning execution.
MLOGIC(CHECK): %IF condition %symexist(TEST)=0 is FALSE
MLOGIC(CHECK): Ending execution.
37
AJ_Brien
Quartz | Level 8
I tried this too:

%macro check;
%if "&test." = ' ' %then %do;
%let test = 'cycle = 0';
%end;
%mend;
%check;

%put &=test ;

Log:
26 %macro check;
27 %if "&test." = ' ' %then %do;
28 %let test = 'cycle = 0';
29 %end;
30 %mend;
31 %check;
MLOGIC(CHECK): Beginning execution.
SYMBOLGEN: Macro variable TEST resolves to
MLOGIC(CHECK): %IF condition "&test." = ' ' is FALSE
MLOGIC(CHECK): Ending execution.
32
33 %put &=test ;
SYMBOLGEN: Macro variable TEST resolves to
TEST=
Tom
Super User Tom
Super User

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

SASKiwi
PROC Star

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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