while you were sleeping… sas is hard at work andrea wainwright- zimmerman

17
While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Upload: maximillian-underwood

Post on 19-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

While You Were Sleeping…SAS Is Hard At Work

Andrea Wainwright-Zimmerman

Page 2: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Overview

Bomb-Proof The Code Handle Any Errors Store The Log Confirm Success Determine Possible Scenarios Schedule Code To Run

Page 3: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Bomb-Proof The Code

Any SAS code that you plan to schedule needs to be as error free as possible.– No syntax errors– Run many time through all possible scenarios

without errors or issues

Page 4: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Handle Any Errors

No matter how well written the code, there still may be unavoidable errors.

Where in the code can they happen? What methods can be used to catch these errors? How should they be handled?

Examples:– Bad data provided – Database is down– Password has expired

Page 5: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Handle Any Errors - Bad Data

Determine what types of bad data are possible. Code logic to catch such issues. Send notification of the data issue.

– Both to you and the data provider if possible– Provide noticeable, clear subject line– Determine what useful details to include in the body

Skip over sections of code that shouldn’t (or won’t) run on the bad data.

– GOTO and LINK are helpful– If no more code is needed ENDSAS is an option

Page 6: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Handle Any Errors - Database Issue

To capture an issue with the connection to a database, use the following %check libname macro immediately after the libname statement

%macro check_libname; %if &sysdbrc ne 0 %then %do; %send_email(subj=LIBNAME FAIL ,text=%superq(sysdbmsg)) endsas; %end;%mend;

Page 7: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Store The Log

No matter how well you write the code, and no matter how well you plan for all possible issues, there still is a chance of failure.

In these cases you’ll need to review the log to see what happened.

proc printto log="C:\My Documents\ project\log_&sysdate..log" new;

run;

Page 8: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Confirm Successes

At certain points in the process you will want to be notified of successes.

If there is a macro that loops e-mails notifying you of the success of step X of Y can be helpful in catching anomalies.– For example, if you get a message about 2 of 2

but never got a message about 1 of 2, you’ll want to review the log.

Page 9: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Confirm Successes - Send_Email

%macro send_email

( to= &my_e_mail , from=&my_e_mail , subj= , cc= &my_e_mail , text= );

filename sendmail email;

data _null_;file sendmail;

put '!EM_TO!' "&to";put '!EM_FROM!' "&from";put '!EM_CC!' "&cc";put '!EM_SUBJECT!' "&subj";body="&text";put body;

run;%mend;

Page 10: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Confirm Successes - Outlook Issues

Outlook will want to know if you really want the e-mail sent.

This defeats the purpose of having the code run overnight and report on it’s progress.

There are a few options to handles this.

Page 11: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Confirm Successes - Outlook Issues

This is an optional Outlook behavior that can be turned off if you have the permissions or can influence those that do.

There are free programs available on-line that will simply “Click Yes” for you that you can install if you have the permissions.

You can edit the SAS CFG file to use SMTP instead.

See http://support.sas.com/kb/19/767.html for details.

Page 12: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Determine Possible Scenarios

Will the code always produce something? Will there always be something the code

needs to do? Are there iterative loops (macros) that

notification would be beneficial for?

Don’t leave yourself wondering what happened.

Page 13: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Determine Possible Scenarios

StartAble to

Connect to dB?

Failure E-mail

Is There New Data?

EndNo New Data E-

mailEnd

Data Correct?

Failure E-mail End

Determine How Many Iterations

Run MacroE-mail X of YDone All

Iterations?Completion E-mailEnd

No

Yes Yes

Yes

No No

Yes

No

Page 14: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Schedule Code To Run

Does this code need to run on a repeating schedule or do you just want it to run after hours?

To run SAS after hours, use the SLEEP function.

For repeating running, each environment has it’s own scheduling tool.

For Windows, there is the Scheduled Task.

Page 15: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Schedule Code To Run - Sleep

To SLEEP till a specific start time:

data _null_; now=datetime(); start=’25JUN2010:19:00:00'dt; wait_sec=start-now; zzz=sleep(wait_sec);run;

Page 16: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Schedule Code To Run - Sleep

To SLEEP for a set amount of time:

data _null_; hour=5; min=30; wait_sec=(60*60*hour)+(60*min); zzz=sleep(wait_sec);run;

Page 17: While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman

Questions?

Andrea Wainwright-Zimmerman

[email protected]