BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dl0324
Fluorite | Level 6

Hi all,

 

I'm looping through unique values of a variable that I use to create charts using call symput. But some of the values contain special characters like apostrophe and that's where I run into issues. How do I tell SAS to mask any special characters stored in my macro value? Below is my sample code (and the red text is where i get into trouble when the custname value is, for example, "CUST'A":

 

 

data _null_;
set topcust1;
call symput('custname'||left(_n_),strip(custname));
call symput('stop',left(_n_));
run;


/*CREATE CHARTS*/

%macro createplots;
%do i=1 %to 10;title1 J=C font="&font/bold" H=13pt "PRICE CHART BY CUSTOMER: %upcase(&&custname&i.))";


proc gplot data=data1 (where=(custname="&&custname&i."));
plot price*date = group/ 
skipmiss
haxis=axis1 
vaxis=axis2 
run;quit;
%end;
%mend;



ods _all_ close; 
ods listing; 
ods pdf file="&outpath\&file.";
%createplots;
ods pdf close;
quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Use %bquote function to mask the resolved macro var value

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Use %bquote function to mask the resolved macro var value

Tom
Super User Tom
Super User

Here is one way that the data step which generates the macro variables can immediately re-create them with macro quoting.

data _null_;
  if eof then call symputx('stop',_n_-1);
  set topcust1 end=eof;
  mvar=cats('custname',_n_);
  call symputx(mvar,custname);
  call execute(catx(' ','%let',mvar,'=%superq(',mvar,');'));
run;

Although in your situation why not just add real quotes?

data _null_;
  if eof then call symputx('stop',_n_-1);
  set topcust1 end=eof;
  call symputx(cats('custname',_n_),quote(trim(custname),"'"));
run;
...
(where=(custname=&&custname&i))
...

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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