Desktop productivity for business analysts and programmers

pass a parameter to SAS EG project.

Reply
N/A
Posts: 0

pass a parameter to SAS EG project.

Hi friends,
I have schedule a SAS EG project . It created a EGScript.vbs file for me to run the project.
I want to know that how can i pass a parameter (eg. say a path of a input file which will be required somewhere in project code). I need to give this EGScript.vbs file to a guy who just need to change the path as per his requirement.
can someone help.
Thank You
N/A
Posts: 0

Re: pass a parameter to SAS EG project.

hey ...if any body knows..... then plssssssss let me know...
tell me if there is some other way of doing it.... Message was edited by: Avi
Super Contributor
Super Contributor
Posts: 3,174

Re: pass a parameter to SAS EG project.

When launching SAS, it is possible to pass a SYSPARM= parameter -- I suggest you explore how you can introduce this parameter into your vbs script as a command invocation parameter, then your SAS program can reference either the automatic macro variable named &SYSPARM, or you can retrieve the SYSPARM= character string using the SYSPARM() function.

The SAS DOC has information about SYSPARM.

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 149

Re: pass a parameter to SAS EG project.

Hi Avi,

I haven't done much with scheduling, but my guess is you're probably going to need to use a %LET statement to assign the path value. Anyone with better ideas please jump in!

So, if the parameter name is PATH1, I would create a Code Node at the top of your project with the code:

%LET path1=c:\whatever;

The person you're giving the project to will have to modify this code by hand to the appropriate path. Verify in the code/task that's using the path that there are double quotes to get the macro variable to resolve correctly.

RIGHT: "&path1\textfile.dat"
WRONG: '&path1\textfile.dat'

To be on the safe side, once you have the %LET in the project I'd then delete the parameter from the parameters manager. My guess is that EG would just sit there waiting for the user to type the parameter value if one is still in the project, but again, haven't tried this. Before you delete the parameter from the Parameters Manager, make sure you have a backup of the project in case my instructions are totally off-base!!

Hope this helps.
N/A
Posts: 0

Re: pass a parameter to SAS EG project.

Hi
Thank you for the replies.
I tried giving some code in the EGscript.vbs like

project.run
project.submit("%let Mpath =%str(D:\SAS\InputFiles);")

This statement creates a Macro variable Mpath which can be resovled any where in project. this macro may be SYSparam also. but
which i hoped it will run as the first code in the project. But it not seems to be working. this code never runs ..... i checked logs
see the guy to which has nothing to do with sas ...My project creates few report based on a input file. the problem is the path to input file cannot be fixed... i have to give the only vbs script to him , and running the script runs the project on server .. and stores the o/p in a folder. so he needs to only modify the path when required in vbs script.
SAS Employee
Posts: 149

Re: pass a parameter to SAS EG project.

Avi,

Are you using the path to point to raw data files (aka flat files), or SAS data sets, or something else entirely? I've got some ideas but wanted to ask that up front.
N/A
Posts: 0

Re: pass a parameter to SAS EG project.

ya , i am using the path to point a rawdata file which is a CSV file.
Super Contributor
Super Contributor
Posts: 3,174

Re: pass a parameter to SAS EG project.

The presumption here is that you need the variable data in your SAS environment. So, you need to determine how/where SAS is being invoked and introduce a SAS run-time CONFIG parameter override, either using SYSPARM= or you can use the IS= (short for INITSTMT= ) where you can supply directly your %LET statement. If you choose SYSPARM, then you can access the string using the SAS automatic variable &SYSPARM, or by using the SAS function SYSPARM() to assign a DATA step variable, as needed, in your application program.

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 149

Re: pass a parameter to SAS EG project.

I think you may be trying to do too much in the VB script and not enough in the project itself. I'm looking at a sample VB script that EG generated for scheduling, and I don't see anything in there that would allow you to set a value for a path. The relevant VB code seems to be:

' Start up Enterprise Guide using the project name
'----
Dim prjName
Dim prjObject

prjName = "C:\workshop\winsas\egqr4\DemoData\Demo.egp" 'Project Name

Set app = CreateObject("SASEGObjectModel.Application.4")
If Checkerror("CreateObject") = True Then
Exit Sub
End If

'-----
' open the project
'-----
Set prjObject = app.Open(prjName,"")
If Checkerror("app.Open") = True Then
Exit Sub
End If

You could explore whether using SYSPARM would allow you to supply the path to EG, as Scott suggests. I don't have much experience with that, but know SYSPARM is designed for situations like this.

Me personally, I would modify the part of the project that's reading the CSV file. Take the code generated by the import data task, copy it, and paste it into a new code node. Add a %let at the top of that code to store the path. Reference that macro variable on the infile statement (as previously posted). Lastly, get rid of the original import data task and any stuff in the parameters manager since the code node is going to handle that part. The end user will have to change the code in the project to meet their needs -- so you'll need to share the project AND the VB script. This may be what you were hoping to avoid... but this is the way I know how to do it. If you get desperate, remember you can say File > Export > Export All Code. This has it's own problems, but it's a good technique to know about.

So, hope you can get this working! I'm sorry I can't be more help on the VB stuff; I get lost once I start venturing outside SAS. Smiley Happy
Community Manager
Posts: 2,697

Re: pass a parameter to SAS EG project.

The EG automation model allows you to access and set values for project parameters -- those parameters that you've defined with the Tools->Parameter Manager.

Here is an example VB script that works with parameters that you've defined in your project.

[pre]
Option Explicit
Dim app
Dim prjName
Dim prjObject
Dim parmList
Dim parm

prjName = "C:\temp\autowithparams.egp" 'Project Name

' start the app and open the project
Set app = CreateObject("SASEGObjectModel.Application.4")
Set prjObject = app.Open(prjName,"")

' discover the parameters
Set parmList = prjObject.Parameters
Wscript.Echo "Project has " & parmList.Count & " parameters."

' work with the first parameter
Set parm = parmList.Item(0)
WScript.Echo parm.Name & " parameter has default value of " & parm.DefaultValue
parm.Value = "M"

WScript.Echo parm.Name & " parameter has been set to value of " & parm.Value

' run the project
prjObject.Run

WScript.Echo parm.Name & " parameter has been set after Run to value of " & parm.Value

prjObject.Close
app.Quit
[/pre]

Chris
N/A
Posts: 0

Re: pass a parameter to SAS EG project.

hey Chris,

I will definitely try this.
I had previously tried written below,but some thing went wrong.

prjObject.code mycode = prjObject.codeCollection.add;
mycode = "%Let mypath=%str(D:\SAS\INputfiles)"
mycode.run

i will let you know the results ..thanks.

regards
Avi
N/A
Posts: 0

Re: pass a parameter to SAS EG project.

Hi chris ...

Thank you very much . The solution you gave was perfect. It worked fine.

Avi
Frequent Contributor
Frequent Contributor
Posts: 94

Re: pass a parameter to SAS EG project.

@Chris,

The code example you provided allows for a parameter's value to be set using its numerical index, but is there a method that allows it to be set by name?

The only method I've found, which seems a strange approach, is to parse the list of parameters until I match the required name and then set the value. This doesn't seem like the best approach, but I've been unable to find any other way to access a specific parameter.
Community Manager
Posts: 2,697

Re: pass a parameter to SAS EG project.

DF,

No, I don't think there is a better approach right now when using VBScript to automate it. I admit it's a bit klunky...

Chris
Frequent Contributor
Frequent Contributor
Posts: 94

Re: pass a parameter to SAS EG project.

Thanks for clarifying that Chris - I can stop looking now!
Ask a Question
Discussion stats
  • 17 replies
  • 2183 views
  • 0 likes
  • 6 in conversation