DATA Step, Macro, Functions and more

Batch processing, runtime environments, logs and outs

Posts: 0

Batch processing, runtime environments, logs and outs

I had been using a cumbersome batch file to run my SAS processes in unattended batch from a scheduler. All of my batch SAS programs recognize if they are running in the PRODuction, TEST or DEVelopment environments, but the DOS *.bat batch file couldn't. I finally bit the bullet and found a couple sites to help me learn to use VB scripts. Results are below. It is not short, but it now supports the automatic recognition of user and runtime environment, and lets me provide the same style of date and time stamps on the -log and -out filenames.

I will not use the [ pre ] and [ /pre ] wrappers because they are flaky in function.

Option Explicit

dim BasePath, RunEnvironment

Private sub getPaths(filespec)
dim i
i = instrrev(filespec,"\")
BasePath = mid(filespec,1,i)
i = instr(ucase(BasePath),"\BATCH")
RunEnvironment = mid(BasePath,1,i)
end sub


Function GetUserName
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
GetUserName = objNetwork.UserName
End Function

Function DateStamp
dim dummy : dummy = now()
Dim mm : mm = Right("00" & Month(dummy), 2)
Dim dd : dd = Right("00" & Day(dummy), 2)
Dim yyyy : yyyy = Year(dummy)
DateStamp = yyyy&"-"&mm&"-"&dd
End Function

function TimeStamp
dim dummy : dummy = now()
dim hh : hh = right("00" & hour(dummy), 2)
dim mm : mm = right("00" & minute(dummy), 2)
dim ss : ss = right("00" & second(dummy), 2)
timestamp = hh&mm&ss
end function

function today
today = WeekDayName(Weekday(now()))
end function

function script_name
dim i
i = instrrev(WScript.ScriptName,".")
script_name = mid(WScript.ScriptName,1,i)
end function

provides all the functionality that I'm after for:

batch_logname = BasePath &"logs\" &GetUserName &"\"&script_name&datestamp&"."&timestamp&"."&today& ".log"


sas_log = " -log """ &RunEnvironment& "logs\" &GetUserName& "\" &SAS_process& "." &datestamp&"."&timestamp&"."&today& ".log"" "
sas_out = " -out """ &RunEnvironment& "logs\" &GetUserName& "\" &SAS_process& "." &datestamp&"."&timestamp&"."&today& ".lst"" "

the command that actually executes the SAS program is:

objShell.Run (SAS &RunEnvironment&"play\"&SAS_process &" -batch -nosplash" &sas_log & " -sysparm ""5"" ",1,true)
Ask a Question
Discussion stats
  • 0 replies
  • 1 in conversation