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;
Use %bquote function to mask the resolved macro var value
Use %bquote function to mask the resolved macro var value
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))
...
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.