BookmarkSubscribeRSS Feed
elwayfan446
Barite | Level 11

I have an interesting challenge that I hope someone can help me with.

 

I have a process flow inside a SAS EG project that I scheduled in order to generate the .vbs file. I would like to call this file with a .cmd file like I do with many other projects I have.  However, this one is different.

 

Here is the challenge:

 

Inside the process flow, I have a task that pops a prompt from the prompt manager which asks for a date.  Once this date is put in, the process runs using that date in criteria throughout the tasks where it is needed.  My goal is to be able to kick this process off with the .cmd file but the problem is that it ignores the task with the prompt.  What I need to happen is for the prompt to still appear to the end user so a date can be entered, even though SAS EG is not open.  Is this even possible?

 

Thanks!

12 REPLIES 12
SuryaKiran
Meteorite | Level 14

You can assign an environment variable from command line with date & modify the SAS EG code to include %sysget() to assign value if run from command line or prompt for value if run in EG. 

Thanks,
Suryakiran
elwayfan446
Barite | Level 11

@SuryaKiran 

 

I am not quite sure I follow.  Would you be able to give me an example and explain how that ties into the .vbs file that runs the process flow in EG?

SuryaKiran
Meteorite | Level 14

I assume your vbs is attempting to run a SAS project (.egp file). Since your .egp is developed in such a way that it prompts for a value before running. I assume you are trying to schedule the job through vbs, so for that you may need to remove prompt and come up with assigning values from vb script or from command line. 

 

currently if you look at the code in the project, &date (or something similar) will be in the code that takes up the value provide through prompt. You need to change this to get the value from where it is defined. 

 

something like in your code you can add %let date=%sysget(date_value);

 

Now your vbs need to be modified to assign environment variable date_valu="value you want to pass". Each time you run the vbs, this date values need to be changed accordingly.

Thanks,
Suryakiran
elwayfan446
Barite | Level 11

1.  Yes, it is attempting to run the .egp file (a process flow inside of it).

2.  Yes, there is a date inside a program within the process flow in which the prompt takes the date entered by the user and populates the criteria.

 

What I don't understand is how to edit the .vbs to assign an environment variable that will be passed along to the code in the process flow.  I also don't understand how the end user will be able to change this date anytime they run it without having to change code.  These users don't understand code and simply need a box to pop up that they enter a date into.

elwayfan446
Barite | Level 11

While I am waiting to hear back from @SuryaKiran, I am hoping to hear some input from other users as well.  @Reeza & @ChrisHemedinger, would you happen to have any ideas for this?

 

Thanks!

elwayfan446
Barite | Level 11

@Reeza 

 

I looked at the post and I am trying to determine where it fits in to what I am doing.  Is it in the code inside the EG process flow?

 

Let me take a step back, I may have confused the issue.  So, when I created the process flow, I scheduled it based on the schedule creator inside EG.  It automatically generates a .vbs file and adds it to the windows scheduler to run.  Windows scheduler runs the .vbs file directly.  There is no .cmd file involved in that scenario.

 

In my case, I don't use the task scheduler to kick of a .vbs file for a process, I use a .cmd file to kick it off.

 

@echo off

wscript "\\pncbank.com\corp\NECD\Group\PFS\mortgage\MSR Reporting\Automation\SAS EG Project Automation\FHLMCDaily.vbs"

If you run the process flow manually with EG open and you have a prompt that was created in prompt manager, once the process gets to the task calling for the prompt, I enter a date and that is passed to the variable in the code and it completes.  I am wanting that prompt to pop for the user if the .vbs file is run without EG being open, regardless of how the .vbs file is being executed.

 

Maybe this article can do that but I am having trouble determining how to apply it.

Reeza
Super User
I would change my process. Have VBS ask for the parameters and pass them to EG. I don't believe that when you're running via batch you can have that interactive component, so you need to have the user provide the information in some other manner. You could use either a reporting services function which is very useful, create dashboards if you have a tool. You could also create processes based on excel if you have the Add in. Expanding on the approach you already have would be changing the VBS to ask for a parameter and then passing that to the batch script/eg task via SYSPARM option as illustrated in that link.
elwayfan446
Barite | Level 11

Ok.  I am like @SuryaKiran in the fact that I don't work with .vbs very often.  I have just been able to muddle my way through the files the scheduler in EG generates.

 

I will see if I can figure out what you are telling me should work.  I don't have access to the tools you mentioned, just EG at the moment. I may have to try and approach this another way all together.

 

I appreciate all of the help.

ChrisHemedinger
Community Manager

In the EG scripting model, the Project object has a property called Parameters.  This returns a list of the prompts that you have defined in the project.  You can use this to set the values for each prompt (again, called a ProjectParameter -- sorry for the terminology confusion).  

 

If a prompt UI is needed, you can use VBS methods to create the prompt and collect the value to pass.  It will be a simpler, less rich UI than you would have when running the project in EG interactively.

 

Or, as others have said, you could ditch the prompts in your EG project and instead use VB to prompt for the value, and then a Code object to submit a "%let param = value;" segment.  You can create a new Code object in the script, Run it, and then run the rest of your project or flow.

 

I don't have a ready example of using ProjectParameter.  Here's an example of using the Code object to add/run a new piece of code.

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
elwayfan446
Barite | Level 11

So I looked at that example and it looks a bit different than the vbs file generated by EG when I created a schedule.  Again, I have not programmed in vbs much at all.  I like the option of the lest rich UI for the user if possible, I just want them to be able to enter a date as a variable I created in the prompt manager inside EG (i.e. START_DATE).  Here is the vbs code that was generated by EG when I scheduled it.  Trying to determine how I would modify it according to the example you linked to.

 

Option Explicit
Dim app         ' As SASEGuide.Application

Call dowork

'shut down the app
If not (app Is Nothing) Then
    app.Quit
    Set app = Nothing
End If


Sub dowork()
    On Error Resume Next
    '----
    ' Start up Enterprise Guide using the project name
    '----
    Dim prjName     ' As String
    Dim prjObject   ' As SASEGuide.Project
    Dim containerName     ' As String
    Dim containerObject   ' As SASEGuide.Container
    Dim containerColl     ' As SASEGuide.ContainerCollection

    prjName = "L:\MSR SAS Project Development\MASTER DEVELOPMENT FOLDER\Automation\SAS EG Project Automation\SAS EG Automation Projects.egp" ' Project Name
    containerName = "MSR0023 - ALM Bi-Monthly Pipeline Report" ' Container Name
      
    Set app = CreateObject("SASEGObjectModel.Application.7.1")
    If Checkerror("CreateObject") = True Then
        Exit Sub
    End If
    
    Set prjObject = app.Open(prjName,"")
    If Checkerror("App.Open") = True Then
        Exit Sub
    End If
    
        
    '-----
    'Get The Container Collection and Object
    '-----    
    Set containerColl = prjObject.ContainerCollection
    If Checkerror("Project.ContainerCollection") = True Then
        Exit Sub
    End If
    
    Dim i       ' As Long
    Dim count   ' As Long
    count = containerColl.count
    For i = 0 To count - 1
        Set containerObject = containerColl.Item(i)
        If Checkerror("ContainerCollection.Item") = True Then
            Exit Sub
        End If
        
        If (containerObject.Name = containerName) Then
            Exit For
        Else
            Set containerObject = Nothing
        End If
    Next 
    
    If not (containerObject Is Nothing) Then
        '----
        ' Run the Container
        '----
        containerObject.Run
        If Checkerror("Container.Run") = True Then
            Exit Sub
        End If               
    End If
                
    '-----
    ' Save the new project
    '-----
    prjObject.Save
    If Checkerror("Project.Save") = True Then
        Exit Sub
    End If
    
    '-----
    ' Close the project
    '-----
    prjObject.Close
    If Checkerror("Project.Close") = True Then
        Exit Sub
    End If
       
End Sub

Function Checkerror(fnName)
    Checkerror = False
    
    Dim strmsg      ' As String
    Dim errNum      ' As Long
    
    If Err.Number <> 0 Then
        strmsg = "Error #" & Hex(Err.Number) & vbCrLf & "In Function " & fnName & vbCrLf & Err.Description
        'MsgBox strmsg  'Uncomment this line if you want to be notified via MessageBox of Errors in the script.
        Checkerror = True
    End If
         
End Function
SuryaKiran
Meteorite | Level 14

Hello @elwayfan446 

 

I have limited knowledge on VBS, I work mostly on Linux environments. If you have figured out how to assign an environment variables through vbs then later in your sas programs you can alter like below.

 

proc printto log='H:\SAS\test\test_vbs.log';run;

filename myfile "H:\SAS\test\test_vbs.txt";

%macro check();
/* When running EG (with promput below statement will be true */
%if %symexist("username") %then %put "Value passed from prompt"; 
/* If running through vbs then above will be false and then below will try to assign value from system environment variables */
%else %do;
	%let username=%sysget(username);
	%put "Value passed from system variable";
%end;
%mend;
%check; %let datetime=%sysfunc(datetime(),datetime.); data _null_; file myfile; put "&username" "&datetime"; run; proc printto; run;

%check macro will solve your issue, if running through vbs it will take the environment variable value & if run manually it will take the value from the prompt. 

 

 

Thanks,
Suryakiran

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 12 replies
  • 2711 views
  • 2 likes
  • 4 in conversation