BookmarkSubscribeRSS Feed
defaz
Fluorite | Level 6

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

2 REPLIES 2
Astounding
PROC Star

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

ballardw
Super User

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.

 

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