BookmarkSubscribeRSS Feed
cjohnson
Obsidian | Level 7

I found a fantastic article on calling SAS from a VBScript - either in EG or batch.  I am able to get either to work to run a program and get the log.  In the log, I can see that the datasets are created and the proc created output.  However, I can't programmatically access the dataset or the results.  I have looked over the object model, and everything looks like this should work fine.  The log says that 19 records were read for creating the new dataset, and 1 page was created when running a proc.  However, the code object's OutputDatasets and Results collection both have a count of 0.  Idea suggestions would be greatly appreciated.  If it helps, I am running SAS 9.2, EG 4.3.  Here is the code.  Sorry, I couldn't find the <code> tags.

server = "\\nasvs1\Shared\4700Mac\shared2\Actuarial\SAS\"

projname = server & "Testing.egp"

codefiles = Array("LIBNAMES", "WORK")

Set oapp = CreateObject("SASEGObjectModel.Application.4.3")

Set oproj = oapp.Open(projname,"")

Set ocodecollect = oproj.CodeCollection

For Each code In codefiles

  For Each ocode In ocodecollect

  If ocode.Name = code Then

  ocode.Log.SaveAs server & ocode.Name & ".log"

  ocode.Run

  msgbox ocode.Name & ", OutputDatasets: " & ocode.OutputDatasets.Count

  msgbox ocode.Name & ", Results: " & ocode.Results.Count

  End If

  Next

Next

oproj.Save

oproj.Close

oapp.Quit

Christopher Johnson
www.codeitmagazine.com
5 REPLIES 5
Kurt_Bremser
Super User

If the SAS code actually creates a dataset in the library WORK, you won't be able to find anything, because WORK is dynamically created everytime a SAS session starts and deleted when it ends.

cjohnson
Obsidian | Level 7

Wow.  I had no idea.  That did the trick.  You could not see what code I was running in SAS (my mistake), but I was creating dataset in work, running proc means, but the code object did not register any dataset or results.  When I switched to a permanent library, it worked. Thanks!

Christopher Johnson
www.codeitmagazine.com
AndreasMenrath
Pyrite | Level 9

It looks like you are using the EG Automation API. Using this API you can only use the possibilities that the EG API gives you.

Another approach would be to use the SAS Integration Technologies API (see http://support.sas.com/documentation/cdl/en/itechwcdg/61500/PDF/default/itechwcdg.pdf).

Or you give PowerShell and the Cmdlets4Sas a try: Cmdlets4Sas / Wiki / Building a poor man&#39;s enterprise guide

It would also help other people to help you if you would tell what you try to achieve.

cjohnson
Obsidian | Level 7

Thanks!  My goal was just a sample script on my system where I could programmatically interact with the datasets and results.  I appreciate the link to the other API.

Christopher Johnson
www.codeitmagazine.com
cjohnson
Obsidian | Level 7

Sorry to come back to this, but I think I have found the source of my problems.  I run this code in VBScript using the SAS EG API.  The first time I run it, the code file has no datasets or results.  The second time I run it (and subsequent), it does.  If I open the project and delete the dataset and result shortcut, and I rerun the script, it has no results again.  I would seem that even though I am running the code and then trying to access the dataset and results, they aren't there until after the project is saved, and then they can be accessed by the shortcuts.  Any thoughts on this?

ocode.UseApplicationOptions = False

ocode.GenListing = True

ocode.GenSasReport = False

ocode.Log.SaveAs server & "Results\" & ocode.Name & ".log"

ocode.Run

ocode.SaveAs server & "Results\" & ocode.Name & ".sas"

msgbox ocode.Name & ", OutputDatasets: " & ocode.OutputDatasets.Count

msgbox ocode.Name & ", Results: " & ocode.Results.Count

For n=0 to (ocode.OutputDatasets.Count -1)

  dataName = ocode.OutputDatasets.Item(n).Name

  ocode.OutputDatasets.Item(n).SaveAs server & "Results\" & dataName & ".xls"

Next

For n=0 to (ocode.Results.Count -1)

  ocode.Results.Item(n).SaveAs server & "Results\" & WScript.ScriptName & n & ".lst"

Next

Christopher Johnson
www.codeitmagazine.com

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1071 views
  • 0 likes
  • 3 in conversation