09-11-2013 09:24 AM
I'm having a problem with a macro I'm trying to write to display titles in a sas template
the macro goes as follows:
Step one: compile macro variables
select count(distinct titles)
select distinct titles
into :%nrstr(titlemacr1) - :%nrstr(titlemacr%left(&n))
Step II: Execute a macro to generate graphs with a unique title as follows:
%do i=1 %to &n;
The problem i'm having is that the entrytitle statement will not resolve if the string which &&titlemacr&i resolves to contains any quotes. For example, if titlemacr resolves to ABCD, the macro is fine. if titlemacr resolves to ABC"D the macro generates an error and does not work.
Am I going about the sysfunc/nrquote functions incorrectly?
09-11-2013 09:59 AM
That didn't quote work -- I still receive an error along the lines of 'the function quote referenced by %sysfunc has too many arguments
The macro variable in question has a double quotes attached to two numbers followed by blank space. It seems like the function tries to resolve when it sees that quote, and that's where the issue beings.
09-11-2013 10:15 AM
You should check that PROC TEMPLATE handles these characters properly by creating an example without macro logic or macro variables. For example if TITLEMACR1 contains ABC"D then you would want to test if
entrytitle "ABC""D" ;
Note: You can simplify the SQL that is generating the macro variables. You can also put the call to QUOTE() function there and avoid issues with macro variable expansions.
proc sql noprint ;
select distinct quote(trim(titles))
into :titlemacr1 - :titlemacr99999
%let n=&sqlobs ;
entrytitle &&title1macr&i ;
09-11-2013 11:00 AM
Still not quite working, however the template does resolve if there are quotes within quotes, e.g. entrytitle "ABC""D" does resolve.
Further, if i try out the following:
the macro resolves, too. it apepars that the double pass of the macro creates an issue.