BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HN2001
Obsidian | Level 7

Hi,

 

I'm putting together some code to check valid values.  If it isn't in the valid values, it would be put into the dataset, tmp.

However, one of the valid values contains an ampersand.  How do I trick SAS so it doesn't think it is a macro.

 

I have simplified the code I actually wrote to the part I'm having issues with

 

data Test_Data;
    input Person $ Color $20.;
    datalines;
Person1 Black&White
Person2 Purple
Person3 Black&White
Person4 Blue
Person5 Red
;
run;
 
%macro colorchk(var1,var2);
data tmp (keep=Person Color);
set Test_Data;
if &var1. ^in (&var2.);
run;
%mend colorchk;
%colorchk(Color,"Black&White" "Purple" "Blue" "Red");
 
When you run this, you get this in the log:
WARNING: Apparent symbolic reference WHITE not resolved.
WARNING: Apparent symbolic reference WHITE not resolved.

Is there a way to code so this warning doesn't happen??
 
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Just use single quotes around the value instead of double quotes and the macro processor will ignore the content of the string.

%colorchk(Color,'Black&White' "Purple" "Blue" "Red");

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Just use single quotes around the value instead of double quotes and the macro processor will ignore the content of the string.

%colorchk(Color,'Black&White' "Purple" "Blue" "Red");
HN2001
Obsidian | Level 7

Thanks Tom!

 

That does seem to work.  A similar question, I also have a pdf with frequencies being produced.  in this pdf, I was also outputting the valid values from the macro statement.

However, the warnings also appear for that too.

 

This is the code I have:

ods pdf text="^{style [font_face=arial font_weight=Bold font_size=14pt color=blue just=center] &var1.}";
proc freq data=Test_Data;
table Group*&var1./list missing;
run;
ods pdf text="^{style [font_face=arial font_size=12pt color=blue just=center] &var1. has no out of range observations}";
ods pdf text="^{style [font_face=arial font_size=12pt color=blue just=center] Possible values: %bquote(&var2.)}";

The last line is what also gives the warning:

WARNING: Apparent symbolic reference WHITE not resolved.
WARNING: Apparent symbolic reference WHITE not resolved.

 

Tom
Super User Tom
Super User

If you don't want the & evaluated then don't use %BQUOTE().  That is one of the main reason TO use %BQUOTE() is to quote values that are enclosed in single quotes.

 

You might use %SUPERQ() instead to add macro quoting.  Pass just the NAME of the macro variable whose value you want quoted.

ods pdf text="^{style [font_face=arial font_size=12pt color=blue just=center] Possible values: %superq(var2)}";
HN2001
Obsidian | Level 7

Tom - Thank you so much for your help!  It cleaned up the log and still gave me the output I was looking for!  Thanks again

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 1136 views
  • 1 like
  • 2 in conversation