Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to submit batch jobs in SAS Programming using task scheduler

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I've tried using the task scheduler to submit batch jobs, but the result was- could not start.

So, anyone knows how to solve this problem?
thanks
 
Hi,

I can do this with Vbscript and Windows Scheduler if you still need it

Danny
 
dmksas, please post your method for using vbsrcipt and Windows Scheduler.

I have been playing around with using VBA to run SAS with some success, but I am always interested in seeing new methods.
 
Using VBA to run SAS, are you using IOM or OLE? I have a lot of experience in utilising IOM from VB, VBA and vbscript.

The batch method requires vbscript..

This is the contents of a vbscript file that I use.. what it does is check a location for SAS program files, if one is found it batch submits it..

Code:
Dim fs, f, fc, f1, Ret
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder([b]Input Location of folder containing sas program files[/b])
Set fc = f.Files
For Each f1 In fc
  If f1.Name <> "" Then
    Set Ret = WScript.CreateObject("Wscript.Shell")
    Ret.run "C:\PROGRA~1\SASINS~1\SAS\V8\SAS.EXE " &chr(34) &"%1" &chr(34) &" -noprint -nologo -config C:\PROGRA~1\SASINS~1\SAS\V8\SASV8.CFG -log [b]place to save the log[/b] -sysin [b]Folder where program is held[/b] " & f1.name
    set ret = nothing
  Else
    MsgBox "No File Found to execute"
  End If
Next

The text in bold is where you will need to change, anything inside the ret.run will need to be in shortpath format.
 
Here is the code that I have adapted. I am still in the testing phases of my end application, but the idea is that I use VBA to check for the existence of certain required files and windows folder structure. If they are not in place then VBA will either warn the user or create the needed resource when possible

Then I run the SAS code and do some file maintenance the notifications with VBA when SAS finishes.

The objective is to automate all of the external aspects of my SAS production so that someone else can just kick off and monitor the results of the job.

Code:
[COLOR=green]'"Microsoft ActiveX Data Objects 2.5 Library" and
'"SAS: Integrated Object Model (IOM) 1.0 Type Library" and
'"SASWorkSpaceManager 1.0 Type Library"[/color]

Dim obWS As SAS.Workspace
Dim obWSM As New SASWorkspaceManager.WorkspaceManager
[COLOR=green]'Code from web site  [/color][URL unfurl="true"]http://www.ratcliffe.co.uk/note_colon/note07.htm[/URL]

Sub Form_Load()
Dim obConn As New ADODB.Connection
Dim obRS As New ADODB.Recordset
Dim errorString As String

[COLOR=green]'start the SAS session
 [/color]Set obWS = obWSM.Workspaces.CreateWorkspaceByServer("Local", _
    VisibilityProcess, Nothing, "", "", errorString)

[COLOR=green]'submit some SAS code
 [/color]obWS.LanguageService.Submit _
     "data a; do x=1 to 10; y=10*x; output; end; run;"

[COLOR=green]'open an ADO connection to the data set
 [/color]Dim connString As String
connString = "provider=sas.iomprovider.1; SAS Workspace ID=" _
             + obWS.UniqueIdentifier
obConn.Open connString
obRS.Open "work.a", obConn, adOpenStatic, adLockReadOnly, _
          adCmdTableDirect

[COLOR=green]'write the table as html (visible in Word with tags)
 [/color]obRS.MoveFirst

Dim sTable As String
sTable = "<TABLE BORDER=0><TBODY><TR><TD class=Data>"
Selection.TypeText sTable

sTable = obRS.GetString(, , "</TD><TD class=Data>", _
    "</TD></TR><TR><TD class=Data>")
Selection.TypeText sTable
sTable = "</TD></TR></TBODY></TABLE>"
Selection.TypeText sTable

[COLOR=green]'tidy-up [/color]
obRS.Close
obConn.Close
obWS.Close

End Sub
 
The batch file submission is easily converted to vba, and it is more controllable (vbscript only supports variant)

If you want to use it inside vba then inlude the reference to "Windows Script Host Object Model" inside the reference.

You can just import directly into access via PC File Formats, but you will need this licensing by SAS, it is however quicker than opening a connection through ADO.

If you want my batch file submission converting to VBA then let me know
 
Chew Ling,
Lets get something straight. What do you want to do? Do you want to run a SAS pgm from the task mgr. I must warn you that the task manager in any windows environment is not stable. We use it quite often, but every few days something happends that throws the task mgr off.

Your question was what can go wrong that will block the job from executing.... Let me list the things that we hit.

1) the task mgr runs as a user if none is selected it uses the default windows machine id. On most office networks this doesn't allow proper file access, so the task mgr simply stops and exits. On a few a occasions (before we realized this) it ran for the max time limit, 72 hours!! (Like who would ever run this for that long???? MSoft!!) This can be corrected by manually selecting the run-as (user) option. You must enter the user's password or this will not run correctly.
2)Selecting the run frequency can be annoying. What I mean is we selected run every day, yet when we logged out-in the run once was selected. So check that as well.
3) Some times the user machine that you use (server's too) do not have the access rights to run the complete sas program. We ran into this when we moved a program from the programmer's machine (who had access to god knows everything) to a work station that had limited access to the same network. Task mgr doesn't tell you thats what happened. It runs and closes as if it completed the task.
4)I also did not like the batch sas modules. I could never get them to work right in a normal windows env. the Rsubmit commands simply did not work. Perhaps that client didnt license that feature. who knows. What I realized you can do (using windows only) is use the autoexec command on the command line. What this does is execute the sas program that is passed to this command on startup. So in a SAS shortcut I put my SAS shebang line (pointer to the sas.exe file) and used that command like this:

"d:\sas8\sas.exe" -autoexec "c:\test.sas"

Now your test.sas file could be a pointer to another whole set of SAS pgms like this:

Code:
%inc "yourcompletesasfile.sas"
endsas;***ENDS SAS WHEN FINISHED ***;

You can now take the above example and use that in the task mgr. Now if you want to get fancy you can use the scheduler command line args to initiate and schedule direct from SAS but thats another topic, and as I said earlier extremally unstable.

Hope this helped you.
Klaz
 
However,

using a vbscript file placed on a server installed with sas, and using windows scheduler running this file every couple of minutes I have been able to offer up gui interfaces that submit sas code to the server for the server to run and return the results, without the need for the client's even needing any part of SAS installed.

Basically your non-SAS people have been able to use the power of SAS without them having to type one line of code.

We are talking about window's scheduler here not taskmgr.

Danny

Never Think Impossible
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top