DATA Step, Macro, Functions and more

Macro %bquote and unbalanced closing parenthesis

Occasional Contributor
Posts: 16

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;
  proc append base=&target data=tail;
%mend webout;

For html, it works like a charm.


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

                        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 */
                        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?




Super User
Posts: 6,933

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



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


%webout (html, %superq(snippet) )

Super User
Posts: 13,941

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,'()[]{}','ûùÿÖÜ¢');

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
  • 3 in conversation