Hope someone can help. I am trying to create a routine to run SAS from VBA. I do this with SAS Workspace Manager. As I walk quite far from my comfort zone, I mainly followed what I found in these two sources . Here is what I came up with so far in VBA:
Public Sub SubmitSasProg(usrid As String, passid As String, path As String, sasprog As String, varinput As String, Optional logreturn) Dim obWsMgr As New SASWorkspaceManager.WorkspaceManager Dim obSAS As SAS.Workspace Dim xmlInfo As String Set obSAS = obWsMgr.Workspaces.CreateWorkspaceByServer("Local", VisibilityProcess, Nothing, usrid, passid, xmlInfo) Dim obStoredProcessService As SAS.StoredProcessService Set obStoredProcessService = obSAS.LanguageService.StoredProcessService obStoredProcessService.Repository = "file:" & path obStoredProcessService.Execute sasprog, varinput If IsMissing(logreturn) Then logreturn = 100000 MsgBox obSAS.LanguageService.FlushLog(logreturn) End Sub
And I have a small SAS program, name it "Test.sas":
%let loopTimes=3; *ProcessBody; data a; do x= 1 to &loopTimes; y=x*x*x; output; end; run;
Now this line will work fine:
Call SubmitSasProg("myuserid", "mypassword", "somepath", "Test", "loopTimes=10")
But whenever I try to execute a SAS procedure that modifies files / libnames, etc., I will get either "Invalid operation for this SAS session" or "User does not have access." Please note that I use SAS locally and not on the server. Therefore, I assume that I am not correctly registered in my SAS work and have not received permission. I thought the userId and password parameters in CreateWorkspaceByServer should be logged in.
So my question will be how to successfully start a SAS session with my credentials on my local computer and get all normal access by opening a window.
To clarify, this SAS process will work fine in a windowed environment:
Data _NULL_; *x del C:\WINDOWS; x mkdir C:\Users\Myname\Desktop\NewFolder; run;
But it will not work with the code "Invalid operation for this SAS session" if it is started with VBA. Something similar happens if I try to write SAS datasets.
I searched for a while, but most of the threads are related to SAS server sessions. Any help would be appreciated.