SAS:引用问题

SAS: Quoting Problems

我正在尝试从 SAS 中生成脚本。不幸的是,我需要写行

strMSHTA = "mshta.exe ""about:<input type=file id=FILE>" _
      & "<script>FILE.click();new ActiveXObject('Scripting.FileSystemObject')" _
      & ".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>"""

要将脚本写入文件,我使用以下方法:

/* write the script to file */
filename outfile ".\temp.vbs";
data _null_;
  file outfile;
  put 'WScript.Echo "Hello, World!"';
run;

/* run the script */
data _null_;
  call system(".\temp.vbs");
run;

/* housekeeping */
%let rc=%sysfunc(fdelete(outfile));
%symdel rc;
filename outfile clear;

不幸的是,put 声明对 &'" 并不友善。我已经尝试了所有 macro quoting functions,但无法正常工作。如有必要,我可以使用重载连接运算符 + 而不是 &。由于 ActiveXObject('Scripting.FileSystemObject') 上的单引号,这样做只会留下中间行的错误。有什么想法吗?

不确定我是否理解这个问题。在文字字符串的外部使用单引号而不是双引号将消除对 &% 等宏触发器的担忧,但您仍然需要将任何文字单引号字符加倍需要生成。

put 
 'strMSHTA = "mshta.exe ""about:<input type=file id=FILE>" _'
/'      & "<script>FILE.click();new ActiveXObject(''Scripting.FileSystemObject'')" _'
/'      & ".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>"""'
;

您还可以将字符串文字分成多个字符串文字,并为每个字符串文字使用不同的外引号。

put 
 'strMSHTA = "mshta.exe ""about:<input type=file id=FILE>" _'
/'      & "<script>FILE.click();new ActiveXObject('
 "'Scripting.FileSystemObject'" 
 ')" _'
/'      & ".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>"""'
;