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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 376 views
  • 1 like
  • 2 in conversation