title: Replacing quotes in a SAS macro variable
body: <p>Consider the following sas code fragment:</p>
  
  <pre><code>%macro temp(querystr=);
    filename request temp;
  
    data _null_;
      file request;
  
      put "&lt;string&gt;&amp;querystr&lt;/string&gt;";
    run;
  %mend temp;
  
  %temp(querystr="term 1" and "term2");
  </code></pre>
  
  <p>Note that this piece of code will not compile because the first quote in querystr will close the starting quote of the put statement when the compiler replaces querystr in the data step.</p>
  
  <p>I would like to mask the quotes in the query string to transform it to a valid xml fragment, like:</p>
  
  <pre><code>&lt;string&gt;&amp;quot;term 1&amp;quot; and &amp;quot;term 2&amp;quot;&lt;/string&gt;
  </code></pre>
  
  <p>Is there a way to output the above line to the file with proper masking of the quotation marks? I tried the %sysfunc(TranWrd()) function in combination with masking functions like %nrbquote() etc but so far I haven't found a working solution. Any help is appreciated!</p>