【发布时间】:2017-03-10 08:59:15
【问题描述】:
我有一个 SAS 程序,它需要许多名称每个月都不同的输入文件。与其将 Windows 资源管理器中的单个文件名更新为 SAS 中的硬编码别名,或者将新文件名复制并粘贴到宏变量中,我希望 SAS 启动一个文件提示,我可以在其中选择输入。我在 Windows 7 上使用 SAS 9.4。
为此,我编写了一个 VBScript,它打开一个对话框,如果对话框被取消或关闭,则返回所选文件的路径或空白字符串。
' GetFilePath.vbs
Option Explicit
Function GetFilePath()
Dim objExec, strMSHTA, wshShell
GetFilePath = ""
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>"""
Set wshShell = CreateObject( "WScript.Shell" )
Set objExec = wshShell.Exec( strMSHTA )
GetFilePath = objExec.StdOut.ReadLine( )
Set objExec = Nothing
Set wshShell = Nothing
End Function
'WScript.Echo GetFilePath()
GetFilePath()
理想情况下,我想将GetFilePath.vbs 的返回值分配给宏变量。但是,我不清楚该怎么做。我发现的唯一相关信息涉及使用unnamed pipe 将 I/O 流读入数据集。我想如果我能做到这一点,那么我至少可以使用CALL SYMPUT 将返回值分配给宏变量。但是,我无法让 SAS 读取返回值。
我一直在尝试的一个例子是,
filename getfile pipe "C:\temp\GetFilePath.vbs";
data test;
infile getfile;
input path $;
run;
提示打开,但返回值未分配给path。
【问题讨论】: