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

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