I have a SAS program which requires many input files whose names vary each month. Rather than update the individual file names in Windows Explorer to hardcoded aliases in SAS or copy and paste the new file names into macro variables, I want SAS to initiate a file prompt where I may select the inputs. I am using SAS 9.4 on Windows 7.
To this end, I have written a VBScript which opens a dialog and returns either the path of a selected file or a blank string if the dialog is canceled or closed.
' 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()
Ideally, I would like to assign the return value of GetFilePath.vbs
to a macro variable. However, it's not clear to me how to I would do that. The only relevant information I've found deals with reading I/O streams into a data set using an unnamed pipe. I figure that if I can do that, then I could at least use CALL SYMPUT
to then assign the return value to a macro variable. However, I cannot get SAS to read in the return value.
An example of what I've been trying is,
filename getfile pipe "C:\temp\GetFilePath.vbs";
data test;
infile getfile;
input path $;
run;
The prompt opens, but the return value is not assigned to path
.