DATA Step, Macro, Functions and more

Macro %bquote and unbalanced closing parenthesis

Reply
Occasional Contributor
Posts: 15

Macro %bquote and unbalanced closing parenthesis

[ Edited ]

hi to all,

I use a macro to prepare webpages (html and javascript).

%macro webout(target,content,len);
  %put &=content;
  %if "&len" eq "" %then %do;
  	%let len = 200;
  %end; /* if "&len" eq "" */
  data tail;
    length len 8. line $&len str $4096;
.....
	line = str;
	output;
  run;
  proc append base=&target data=tail;
run;
%mend webout;

For html, it works like a charm.

 

But there is an issue, if a javascript-snippet contains an unbalanced closing parenthesis:

  %webout(html,%bquote(    
                        splitArea : {show : true} 
                }] 
            }   );
  ))

The parser takes the closing parenthesis as end of %bquote.

Of course it works If I replace the ");" with a variable:

 

  %let cpsc = )%str(;);  /* ClosingParenthesisSemiColon */
  %webout(html,%bquote(    
                        splitArea : {show : true} 
                }] 
            } &cpsc
  ))

As in some cases the code-snippets are read from external files:

 

Is it possible to do it without the workaround? Other quoting-macro or any other way?

 

thanks,

def

Super User
Posts: 5,099

Re: Macro %bquote and unbalanced closing parenthesis

Worth a try if you are reading the code snippet from an external file:

 

data _null_;

infile 'external.file';

input code_snippet $ 32.;

call symputx('snippet', code_snippet);

run;

 

So bring the code snippet into a macro variable, then try calling the macro with %superq:

 

%webout (html, %superq(snippet) )

Super User
Posts: 10,552

Re: Macro %bquote and unbalanced closing parenthesis

Not seeing your whole project (and I'm fairly sure I don't want to) a kludge that might work could be to establish some special strings that are not used anywhere else in you code that are replaced in the call then swapped immediately before use such as ASCII 150 û which would not be treated as ( but could be replaced with one using the sas translate function.

 

A kludge and fragile and maybe not suitable depending on what you are passing but...

data example;
   probstring = "this has ( and Other ] or { problemvalues";
   encstring = translate(probstring,'ûùÿÖÜ¢','()[]{}');
   recstring = translate(encstring,'()[]{}','ûùÿÖÜ¢');
run;

Data step examples are easier than macro but you could encode your problem value before making it the value of a parameter to a macro then in the first section of the macro decode.

 

Ask a Question
Discussion stats
  • 2 replies
  • 85 views
  • 0 likes
  • 3 in conversation