BookmarkSubscribeRSS Feed
mm4kite
Calcite | Level 5

Hi, I'm using EG automation via a VBScript to batch submit SAS programs from a thrid party editor.  

 

Interactively, SAS EG will set the _SASPROGRAMFILE macro variable to be the fully qualified path and file name of the SAS program running, but EG automation does not set this.  I'm using EG 7.13 HF4 and SAS 9.4. 

 

My VBScript, via file system and file streaming objects, reads in the text from the SAS program, assigns to the Code.Text property and runs.  See below.  It all works fine except I cannot assign librefs, etc. using part of the program path without hard-coding the path in the text of the batch submitted program. 

 

Thanks,

MM

 

Dim fileSys, fReadStream, fileString
Set fileSys = CreateObject("Scripting.FileSystemObject")
Set fReadStream = fileSys.OpenTextFile(sasPgmFile, 1, False)
fileString = fReadStream.ReadAll()

' add the new code object to the project
Set sasPgmObj = EGPrjObj.CodeCollection.Add

' set the results types, overriding Application defaults
sasPgmObj.UseApplicationOptions = False
sasPgmObj.GenListing = True
sasPgmObj.GenSasReport = False

' Set the server and text for the code
sasPgmObj.Server = sasServer
sasPgmObj.Text = fileString
sasPgmObj.Run ' Run the code

7 REPLIES 7
ChrisHemedinger
Community Manager

Why not prepend your fileString variable with the path you want, parsing it from sasPgmFile (or using FileSystemObject methods to get it for you)?  Add a "%LET" statement with that value, then add on the remainder of the program that you read from the file?

 

That puts your VBScript in control of how that value gets set.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
mm4kite
Calcite | Level 5

Thanks Chris, that's a good thought.  We are trying to process this information prior to the program execution on the SASApp server.   However, I'll look into this to see if it is a viable option.

 

So I take it, there's not a way to set a property or something on the EG App or Project Object to tell SAS to set a specific macro then as the SASApp server boots and runs any configuration or autoexec commands?

 

Thanks,

MM 

ChrisHemedinger
Community Manager

You could create/run another Code item before doing anything else, and stuff it full of all of the %LET statements that you want...

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
mm4kite
Calcite | Level 5

Hi Chris,

 

After researching inserting "%global <macrovar>; %let <macrovar>=<saspgmpath>;" to the front of the file stream, I believe this solution will work by updating another program.  

 

Thanks for your help!

 

Regards,

Mark

CaseySmith
SAS Employee

Mark,

 

I'm glad Chris' solution will work for you.  I agree, that sounds like the best route to take.  However, I wanted to provide a little more information for clarity...

 

The "EGPrjObj.CodeCollection.Add" call in your example adds a new program to the EG project (equivalent to interactive File->New->Program).  The key here is that this new program is embedded (stored in the EG project (.egp file)) by default, rather than a shortcut to a .sas file on disk.  This is important because the _SASPROGRAMFILE macro value is empty (two single quotes) for embedded programs, since there is no physical program file to reference.  For example, you'll see this near the top of the log:

 

%LET _SASPROGRAMFILE='';

 

So, EG is generating the code that sets the _SASPROGRAMFILE macro in this case (both interactively and via automation), it just happens to be set to empty, since it is an embedded program (there is no program file).

 

If you add an existing .sas file to an EG project (ex. File->Open->Program, interactively), the _SASPROGRAMFILE macro will contain the path to the .sas file (when run interactively or via automation).  The root problem is there does not appear to be a way to add an existing .sas program (reference/shortcut) to an EG project via automation.  I did not find an API in the current automation interface for doing this.

 

Hope that helps.

 

Casey


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

mm4kite
Calcite | Level 5

Hi Casey, 

 

Thanks for the additional information. 

 

-Mark

jbbell
Fluorite | Level 6

Hi @CaseySmith ,

 

I've been learning the automation interface for about the last week or two.  Got a powershell script that queries an Excel file and passes parameters into SAS filter prompts.  Everything is working, but I am wondering about reusability of the code.  Every time the script is run, a new code node will be added.  Did you ever figure out a way to call an existing program or a way to clean the node up once the code runs?

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
  • 7 replies
  • 3063 views
  • 2 likes
  • 4 in conversation