2016-10-27 71 views
0

我试图从SAS内部生成一个脚本。不幸的是,我需要写行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')上的单引号,这样做只会在中间线上留下一个错误。有任何想法吗?

回答

1

不知道我明白这个问题。在文字字符串的外部使用单引号而不是双引号可以避免需要担心类似于&%这样的宏触发器,但您仍然需要将需要生成的任何文字单引号字符加倍。

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>"""' 
; 
+0

谢谢!我不知道我可以使用双单引号来防止外单引号关闭。我也不知道可以使用'/'来插入回车符。你碰巧知道我可以在SAS文档中找到这些解释吗? –

+0

查看PUT语句的手册页。查找行指针控件的部分。在SAS语言中查找单词的概念页面。 http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p1qge1g4ytqq41n1e8x8s7ugmyst.htm – Tom