I have a SAS EG project with a set SAS_GRID profile. I'm trying to automate it by using SASEGScripting.dll and vbscript. With the dll I'm able to open a project, edit it, save it etc., however it won't connect to the grid. Can someone help please?
Even if I previously open my project manually, set a profile, do a test run and save, the dll asks for credentials (already defeats the purpose of automation):
Worse yet, even if I write my correct credentials, it doesn't work:
This is my vbscript
Dim objApp, objProject Set objApp = WScript.CreateObject("SASEGObjectModel.Application.7.1") WScript.Echo objApp.Name & ", Version: " & objApp.Version Set objProject = objApp.Open("C:\xxx\xxx.egp","") objProject.Run objProject.Save objProject.Close objApp.Quit
During an automation run, the process needs access to your credentials. If they aren't cached in your profile, you need to stage them in a special credentials.xml file. See this SAS Note for details.
Hi Chris, thanks for your input.
I tried following the instructions, however it still didn't work. I created a credentials.xml like this:
<xml FileVersion="7.1"> <credentials> <server name="SASApp_xxx" userid="xxx" password="xxx"/> </credentials> </xml>
Then I tested putting it in various folders, but none worked:
Only folder %appdata%\Roaming\SAS\SharedSettings\7.1 showed any change in behavior: the credential pop-up stopped showing and I got "unable to connect to server" message instantaneously.
Maybe I need to change something in ConfigurationV71.xml file located in MetadataServerProfiles folder? It is currently like this:
<?xml version="1.0" encoding="utf-8"?> <Configuration LastWrittenBy="Engine Configuration Manager" FileVersion="2"> <Profiles /> <Settings> <ActiveProfile>Null Provider</ActiveProfile> <GenerateLocalServer>False</GenerateLocalServer> </Settings> </Configuration>
I suggest that you turn on Application Logging (Tools->Options) and try again. This will generate a CSCRIPT.exe.log file in your app profile directory and that might contain some helpful details.
And you might need to work with SAS Tech Support to help diagnose -- the TS consultants help folks with EG automation questions all of the time. It can be a tricky topic.
Willian has opened one track in Brazil's TS and I've asked for the log Chris mentioned.
But, he could solve his problem by himself (I think he used something like SFTTRAY.EXE to use the CMD of the machine which has SAS E.G. installed).
Accessing this machine, he could automate what he was looking for.
I believe he will post his final solution here.
There was one element about the problem that makes it more difficult: Willian are using SAS E.G. with App-v.
He shares his solution for this moment (below is my understanding of his 'solution'):
**********;
Use Python's scheduler to run Windows' client (end user's machine) commands and, with this commands, access the SAS E.G.'s machine CMD. There, he can run his *.vbs.
He don't think it is perfect because he can't logoff. But he seems to be happy it is working for now.
He shares:
1) Open prompt within the SAS App-V environment (bubble) changing PackageId and VersionId by AppxManifest.xml values:
cmd.exe /appvve:PackageId_VersionId
2) Once you are in the correct machine, run your *.vbs:
c:\windows\syswow64\cscript run_sas.vbs
**********;
Chris and Carlos, thanks a lot for your help. As Carlos said, I eventually was able to solve my problem without needing admin rights or difficult workarounds, here's a step by step for whom might need this in the future:
1. Go to %appdata%\SAS\MetadataServerProfiles folder and make sure your profile is registered in ConfigurationV71.xml as below (replace ... by your values). Obs: If this doesn't work, it is possible that App-V is hiding the correct file, in this case a workaround is to run ITConfig2.exe -> Test SAS Servers -> Next -> Specify which metadata configuration files to use -> "..." -> %appdata%\SAS\MetadataServerProfiles -> Right click ConfigurationV71.xml -> Edit -> Make your changes -> Save -> Close everything
<?xml version="1.0" encoding="utf-8"?> <Configuration LastWrittenBy="Engine Configuration Manager" FileVersion="2"> <Profiles> <Profile> <Name>...</Name> <Description /> <Type>OMS</Type> <Hosts> <Host machine="..." port="..." /> </Hosts> <UseIWA>False</UseIWA> <SaveLogin>True</SaveLogin> <User>...</User> <Password>...</Password> <DefaultServer>...</DefaultServer> </Profile> </Profiles> <Settings> <ActiveProfile>...</ActiveProfile> <GenerateLocalServer>False</GenerateLocalServer> </Settings> </Configuration>
2. From your automation script/service, launch a command prompt inside the App-V bubble (replace PackageID and VersionID with the values you find inside AppxManifest.xml, you can find this file in the root folder of your App-V app, an easy way to find the path is to follow the shortcut to SAS EG)
cmd.exe /appvve:PackageID_VersionID
3. From this prompt, run your SAS automation vbscript by calling the correct cscript version (in my case 32bit SAS in 64bit machine)
c:\windows\syswow64\cscript run_sas.vbs
4. Here's an example of vbscript based on Chris' excellent paper Not Just for Scheduling: Doing More with SAS® Enterprise Guide® Automation
Dim objShell, objApp, objProject, objProgram Dim i, n 'Parameters outDir = "C:\out" 'Load SAS Set objApp = WScript.CreateObject("SASEGObjectModel.Application.7.1") WScript.Echo objApp.Name & ", Version: " & objApp.Version 'Check profiles Set oShell = CreateObject( "WScript.Shell" ) WScript.Echo "Metadata profiles available for " _ & oShell.ExpandEnvironmentStrings("%UserName%") WScript.Echo "----------------------------------------" For i = 1 to objApp.Profiles.Count-1 WScript.Echo "Profile available: " _ & objApp.Profiles.Item(i).Name _ & ", Host: " _ & objApp.Profiles.Item(i).HostName _ & ", Port: " _ & objApp.Profiles.Item(i).Port Next 'Test creating a project, running a program, and saving outputs objApp.SetActiveProfile("...") Set objProject = objApp.New Set objProgram = objProject.CodeCollection.Add objProgram.UseApplicationOptions = False objProgram.GenSasReport = False objProgram.Text = "data work.cars; set sashelp.cars; if ranuni(0)<0.85; run;" objProgram.Server = "..." objProgram.Text = objProgram.Text & " proc means; run;" objProgram.Run objProgram.Log.SaveAs outDir & "\sas.log" For n=0 to (objProgram.OutputDatasets.Count -1) Dim dataName dataName = objProgram.OutputDatasets.Item(n).Name objProgram.OutputDatasets.Item(n).SaveAs outDir & "\" & dataName & ".xlsx" Next 'Close SAS objApp.Quit
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.