Automating SAS through the Power of VB Script
Outline VB Script Custom Log Task Scheduler Job Streams – Daily, Weekly, Monthly Input Files Email Automation
What is VB Script? Scripting Language Automation capabilities
Running SAS From Command Prompt Required SAS Location Code Location Optional Log Location Output Location
Running SAS From Command Prompt “<SAS location> -sysin <code location> -print <output location> -log <log location>”
VB Script “<SAS location> -sysin <code location> -print <output location> -log <log location>”
Custom Log Creation No auto-generated log for VB Script OpenTextFile function Log file location 1-reading, 2-writing, 8-appending True-create, false-don’t WriteLine function
Task Scheduler
Task Scheduler Required Optional General Triggers Actions Conditions Settings
Task Scheduler Required Optional General Triggers Actions Conditions Settings
Task Scheduler Required Optional General Triggers Actions Conditions Settings
SAS Job Streams – Daily Simple %inc statement needed. %inc 'C:\Data\Conference_Paper\Automated SAS Code\Daily\Subcode_1.sas'; %inc "C:\Data\Conference_Paper\Automated SAS Code\Daily\Subcode_2.sas"; %inc "C:\Data\Conference_Paper\Automated SAS Code\Daily\Subcode_3.sas"; Simple %inc statement needed. Can have multiple set up to run daily. As long as main code is set up to run subcodes will also run. NOTE: If your line of code contains a macro variable it will require double quotes.
SAS Job Streams – Weekly %SYSFUNC – macro function that allows code to evaluate SAS functions TODAY() – SAS function will return the value of today. If no format is specified it will show the number of days since January 1, 1960 WEEKDAY() – SAS function that outputs a value from 1 to 7 for the current day of week, e.g. 4 for Wednesday
SAS Job Streams – Monthly Day()- SAS function that returns the day of the month. Above code shows logic to kick off jobs on the 1st day of the month or the 26th day of the month.
Input Files Filename(fileref,file_name) data _null_; Fopen(fileref) Finfo(varname,option) Today() %Macro CheckFile; data _null_; dummy=filename('fle',"C:\Data\Conference_Paper\test.txt"); fid=fopen('fle'); mdfy=finfo(fid,'Last Modified'); mdfydte=input(mdfy,datetime.); today=today()*24*60*60; if fid=0 then filesready=2; else if mdfydte >= today then filesready=1; else filesready=0; call symput('filesready', filesready); run; %mend;
Input Files &filesready 1=good 0=old 2=doesn’t exist
Input Files &filesready 1=good 0=old 2=doesn’t exist
Automate Emails SAS function FILENAME -allows SAS to send an email electronically. &syscc =0 if successful &syscc =4 if there were warnings &syscc all other values if errors. creation of the &syscc_old macro variable allows jobs to continue running.
Automate Emails –Cont. Within each email code you can add to:, cc:, subject: and the attachment. Put statements allow for further detail.
Automate Emails –Cont. Adjust config file Config file is a text file named SASV9.CFG and will be saved in the same spot where SAS is installed config might change depending on the email server used on your computer.
Conclusion Improve Automated Processes by: Kick off SAS using VB script and a task scheduler Custom Log Run Daily, Weekly, and Monthly Jobs Check for input files Email automation
Contact Information Name: Lindsey Whiting Company: Kohler Co. City/State: Kohler, Wisconsin Phone:920-457-4442 x72745 Email: Lindsey.Whiting@kohler.com
Contact Information Name: Joey Kaiser Company: Kohler Co. City/State: Kohler, Wisconsin Phone:920-457-4442 x70503 Email: Joseph.Kaiser@kohler.com