Xml 替换SAS宏变量中的引号

Xml 替换SAS宏变量中的引号,xml,sas,Xml,Sas,考虑以下sas代码片段: %macro temp(querystr=); filename request temp; data _null_; file request; put "<string>&querystr</string>"; run; %mend temp; %temp(querystr="term 1" and "term2"); %宏温度(querystr=); 文件名请求温度; 数据为空; 文件请求; 放置

考虑以下sas代码片段:

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

  data _null_;
    file request;

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

%temp(querystr="term 1" and "term2");
%宏温度(querystr=);
文件名请求温度;
数据为空;
文件请求;
放置“&querystr”;
跑
%修补温度;
%温度(querystr=“术语1”和“术语2”);
请注意,这段代码不会编译,因为当编译器在数据步骤中替换querystr时,querystr中的第一个引号将关闭put语句的起始引号

我想屏蔽查询字符串中的引号以将其转换为有效的xml片段,如:

<string>&quot;term 1&quot; and &quot;term 2&quot;</string>
“术语1”和“术语2”

有没有一种方法可以在正确屏蔽引号的情况下将上述行输出到文件中?我尝试将%sysfunc(TranWrd())函数与掩蔽函数(如%nrbquote()等)结合使用,但到目前为止还没有找到有效的解决方案。感谢您的帮助

只需使用put'foo';相反:

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

  data _null_;
    file request;

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

%temp(querystr="term 1" and "term2");
%宏温度(querystr=);
文件名请求温度;
数据为空;
文件请求;
放置“&querystr”;
跑
%修补温度;
%温度(querystr=“术语1”和“术语2”);
尝试以下操作:

options mcompilenote=all;
%macro temp(querystr=); 
  filename request temp; 

  data _null_; 
    file request; 
    querystr=symget('querystr');
    querystr=htmlencode(querystr,'quot');
    *putlog querystr $;
    string="<string>"!!trim(querystr)!!"</string>";
    put string $200.;
    *put "<string>&querystr</string>"; 
  run; 
%mend temp; 

%temp(querystr="term 1" and "term2"); 
options mcompilenote=all;
%宏温度(querystr=);
文件名请求温度;
数据为空;
文件请求;
querystr=symget('querystr');
querystr=htmlencode(querystr,'quot');
*putlog querystr$;
string=”“!!修剪(querystr)!!"";
放线200美元。;
*放置“&querystr”;
跑
%修补温度;
%温度(querystr=“术语1”和“术语2”);

将带有“quot”选项的htmlencode添加到数据步骤中,并使用%bquote在宏执行之前屏蔽引号

%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"));
%宏温度(querystr=);
文件名请求温度;
数据为空;
文件请求;
string=cats(“”,htmlencode(“'querystr','quot'),“”);
放线;
跑
%修补温度;
%温度(querystr=%bquote(“术语1”和“术语2”);

只要双引号是平衡的,就可以很好地调用宏。因此,不需要强制宏用户对参数进行宏引用。您的宏可以为它们执行以下操作

   %macro temp(querystr=);
     filename request temp;
     data _null_;
       file request;
       s = catx(htmlencode("%superq(querystr)","quot"),"<string>","</string>");
       l = length(s);
       put s $varying. l;
     run;
   %mend temp;

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

   /* check */
   data _null_;
     infile request;
     input;
     put _infile_;
   run;
   /* on log
   <string>&quot;term 1&quot; and &quot;term2&quot;</string>
   */ 
%宏温度(querystr=);
文件名请求温度;
数据为空;
文件请求;
s=catx(htmlencode(“%superq(querystr)”,“quot”),“”,“”);
l=长度(s);
把新台币换成新台币。L
跑
%修补温度;
%温度(querystr=“术语1”和“术语2”);
/*检查*/
数据为空;
填充请求;
输入
把"填入";;
跑
/*日志
“条款1”和“条款2”
*/ 

注意:文件请求是:文件名=C:\DOCUME~1\wroehl\LOCALS~1\Temp\SAS临时文件\u TD1888\#LN00028,RECFM=V,LRECL=256注意:文件请求中写入了1条记录。最低记录长度为26。最大记录长度为26。注意:使用的数据语句(总处理时间):实时0.03秒cpu时间0.00秒这将在tempfile中打印并查询。感谢有用的添加