BookmarkSubscribeRSS Feed
bullman
Calcite | Level 5

Hi all,

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

proc sql;

select count(distinct titles)

     into :n

     from bigset;

select distinct titles

     into :%nrstr(titlemacr1) - :%nrstr(titlemacr%left(&n))

     from bigset;

quit;

Step II:  Execute a macro to generate graphs with a unique title as follows:

%macro titleloop;

%do i=1 %to &n;

proc template;

...

...

     entrytitle %sysfunc(%nrquote("&&titlemacr&i");

...

...

end;

run;

%end;

%mend;

%titleloop;

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?

5 REPLIES 5
data_null__
Jade | Level 19

Use QUOTE function something like this untested

entrytitle %sysfunc(quote(%superq(titlemacr&i)));

bullman
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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" ;

works.

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

     from bigset

  ;

%let n=&sqlobs ;

quit;


...

   entrytitle &&title1macr&i ;

...

bullman
Calcite | Level 5

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:

entrytitle %sysfunc(quote(%bquote(&title34)));

the macro resolves, too.  it apepars that the double pass of the macro creates an issue.

Tom
Super User Tom
Super User

If

%bquote(&title34)

works then

%superq(title34)

should also work and so should

%superq(title&i)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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