BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Oligolas
Barite | Level 11

Hi,

I'm quoting a list of variables to process in a data step placed inside a macro.

I can't figure out why I need to remove the second %str to make this step work inside a macro.

Since I get the ERROR: Expected close parenthesis after macro function invocation not found.

What does the macro processor return when processing?

 

How SAS Processes Statements with Macro Activity 

 

%let paramcd=Alfred Louise;
%macro works();
   data want;
      set sashelp.class(where=(Name in ("%sysfunc(tranwrd(%sysfunc(compbl(&paramcd.)),%str( )," "))")
                       ));
   run;
%mend works;
%works;

%macro doesNotWork();
   data want;
      set sashelp.class(where=(Name in ("%sysfunc(tranwrd(%sysfunc(compbl(&paramcd.)),%str( ),%str(" ")))")
                       ));
   run;
%mend doesNotWork;
%doesNotWork;
________________________

- Cheers -

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@Oligolas wrote:

you're both right

@PaigeMiller I'd expect SAS to recognize that the quotes inside %STR are matched?


And yet, it doesn't, because the quotes are not matched. Matched quotes indicate that what is between them is quoted, i.e. is a text string. You have a need for a double-quote character at the end of a text string, followed by a space, followed by a double-quote character to start another text string. You are not trying to quote the text between them.

 

As Tom says, you are passing the the %STR function text that doesn't have characters that need %STR. And so the interpretation is different.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Using quotes or double-quotes as text can get tricky inside the macro processor. You need to indicate that these are considered unmatched double-quotes, by using %" rather than just ". Now both macros work.

 

%let paramcd=Alfred Louise;

%macro works;
   data want;
      set sashelp.class(where=(Name in ("%sysfunc(tranwrd(%sysfunc(compbl(&paramcd.)),%str( )," "))")  ));
   run;
%mend works;
%works

%macro doesNotWork;
   data want;
      set sashelp.class(where=(Name in ("%sysfunc(tranwrd(%sysfunc(compbl(&paramcd.)),%str( ),%str(%" %")))")
                       ));
   run;
%mend doesNotWork;
%doesNotWork

 

--
Paige Miller
Oligolas
Barite | Level 11

you're both right

@Tom I sometimes pass special characters through %STR in other context and didn't expect SAS to crash here.

@PaigeMiller I'd expect SAS to recognize that the quotes inside %STR are matched?

________________________

- Cheers -

PaigeMiller
Diamond | Level 26

@Oligolas wrote:

you're both right

@PaigeMiller I'd expect SAS to recognize that the quotes inside %STR are matched?


And yet, it doesn't, because the quotes are not matched. Matched quotes indicate that what is between them is quoted, i.e. is a text string. You have a need for a double-quote character at the end of a text string, followed by a space, followed by a double-quote character to start another text string. You are not trying to quote the text between them.

 

As Tom says, you are passing the the %STR function text that doesn't have characters that need %STR. And so the interpretation is different.

--
Paige Miller
Tom
Super User Tom
Super User

Why did you add the %STR() to quote something that does not need quoting?  To include quotes in %STR() you need to escape them with %.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1689 views
  • 5 likes
  • 3 in conversation