Desktop productivity for business analysts and programmers

How to set _SASPROGRAMFILE using EG Automation

Reply
New Contributor
Posts: 4

How to set _SASPROGRAMFILE using EG Automation

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

Community Manager
Posts: 2,757

Re: How to set _SASPROGRAMFILE using EG Automation

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.

New Contributor
Posts: 4

Re: How to set _SASPROGRAMFILE using EG Automation

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 

Community Manager
Posts: 2,757

Re: How to set _SASPROGRAMFILE using EG Automation

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

New Contributor
Posts: 4

Re: How to set _SASPROGRAMFILE using EG Automation

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

SAS Super FREQ
Posts: 291

Re: How to set _SASPROGRAMFILE using EG Automation

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

New Contributor
Posts: 4

Re: How to set _SASPROGRAMFILE using EG Automation

Hi Casey, 

 

Thanks for the additional information. 

 

-Mark

Ask a Question
Discussion stats
  • 6 replies
  • 159 views
  • 1 like
  • 3 in conversation