Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3337590
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:16:14+00:00 2026-05-18T00:16:14+00:00

Consider the following sas code fragment: %macro temp(querystr=); filename request temp; data _null_; file

  • 0

Consider the following sas code fragment:

%macro temp(querystr=);
  filename request temp;

  data _null_;
    file request;

    put "<string>&querystr</string>";
  run;
%mend temp;

%temp(querystr="term 1" and "term2");

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.

I would like to mask the quotes in the query string to transform it to a valid xml fragment, like:

<string>&quot;term 1&quot; and &quot;term 2&quot;</string>

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!

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:16:14+00:00Added an answer on May 18, 2026 at 12:16 am

    Add a htmlencode with ‘quot’ option to the datastep and use %bquote to mask the quotes until macro execution.

    %macro temp(querystr=);
    
      filename request temp;
    
      data _null_;
    
        file request;
    
        string = cats('<string>',htmlencode("&querystr",' quot'),'</string>');
    
        put string;
    
      run;
    
    %mend temp;
    
    %temp(querystr=%bquote("term 1" and "term2"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following piece of code: JSONObject json = new JSONObject(); json.put(one, 1); json.put(two, 2);
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following ruby code test.rb: begin puts thisFunctionDoesNotExist x = 1+1 rescue Exception
Consider the following code: $(a).attr(disabled, disabled); In IE and FF, this will make anchors
Consider the following code: void Handler(object o, EventArgs e) { // I swear o
Consider the following code: abstract class SomeClassX<T> { // blah } class SomeClassY: SomeClassX<int>
Consider following snippet code for xml. <rootnode> <child id=child1 ><![CDATA[child 1]]></child> <child id=child2 ><![CDATA[child
Consider following piece of code: declare @var bit = 0 select * from tableA
Consider the following Scala case class: case class WideLoad(a: String, b: Int, c: Float,
Consider following script (it's total nonsense in pseudo-language): if (Request.hostMatch(asfasfasf.com) && someString.existsIn(new String[] {brr,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.