I am trying to write a program that loops over a list of names to create multiple PDFs. It's working fine except that one of the names I need it to loop over contains an apostrophe (single quote). I'd rather not just remove the apostrophe from my data, but can't figure out how to get SAS to ignore it in a string literal. Below is my current code. The problem name occurs as one of the &conf variables that I'm looping over.
*Run report for each conference; %macro runcp; %do i=70 %to &nconfs.; %let conf_name = &&conf&i; %let div_num = &&divs&i; %cpreport; %end; %mend runcp; %runcp;
But you don't have any string literals in your posted code.
It looks like your code is referencing a series of macro variables with numeric suffix on their name. If those macro variables were not created with macro quoting then add it when you create the macro variables in your code.
%macro runcp;
%local i conf_name div_num;
%if %symexist(nconfs) %then %do i=70 %to &nconfs.;
%let conf_name = %superq(conf&i);
%let div_num = %superq(divs&i);
%cpreport;
%end;
%else %put ERROR: Macro &sysmacroname requires NCONFS to exist.;
%mend runcp;
But you don't have any string literals in your posted code.
It looks like your code is referencing a series of macro variables with numeric suffix on their name. If those macro variables were not created with macro quoting then add it when you create the macro variables in your code.
%macro runcp;
%local i conf_name div_num;
%if %symexist(nconfs) %then %do i=70 %to &nconfs.;
%let conf_name = %superq(conf&i);
%let div_num = %superq(divs&i);
%cpreport;
%end;
%else %put ERROR: Macro &sysmacroname requires NCONFS to exist.;
%mend runcp;
The string literals occur in my &conf&i macro variables. In particular, conf73 = Presidents' Athletic Conference. This is the one I need to get working. I replaced &&conf&i with %superq(conf&i) as you suggested and it appears to have worked correctly. Thanks.
In SAS code a string literal is enclosed in quotes, like this:
name = "Presidents' Athletic Conference";
So using your macro variable to generate a string literal shouldn't cause any trouble.
name = "&conf73";
because of the outer quotes.
But trying to assign it to another macro variable without adding either actual quotes or macro quoting will cause issues. Try using one of these methods to add macro quoting.
%let x=%bquote(&conf73);
%let x=%superq(conf73);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.