SlideShare a Scribd company logo
1 of 4
Tips and Tricks for SAS® Program Automation
Adam Hood @ Slalom Consulting
2
Use PROC PRINTTO to put all logs in a designated
directory. This will allow any team member to quickly
find and troubleshoot problems in processes. All too
often teams spend time trying to find the appropriate
logs for a given process.
To further enhance your log files, add a timestamp for
easy sorting and a naming convention for specific
process identification.
Tips and Tricks for SAS® Program Automation
Adam Hood
Slalom Consulting
Abstract
Automating SAS programs can be difficult and result in
overcoming unexpected obstacles. Often automation
forces us to account for edge case scenarios that we
would normally assume won’t be encountered.
The goal of this poster is to help programmers
overcome the ‘gotcha’s associated with building and
troubleshooting automated programs. We will touch
on 3 areas: logging, basic error handling, and system
options.
Logging Tip #1
proc format ;
picture myfmt low-high = '%0Y%0m%0d%0H%0M%0S'
(datatype = datetime) ;
run ;
%let DTstamp =%sysfunc(datetime(),myfmt.);
proc printto log=“/home/ahood/logs/myprocess_&DTstamp..log” new;
Often there are multiple stakeholders for a given
automated job. Emails are a great way to let others know
when jobs finish. However, if you want a more self-
service approach or you want to build dependencies with
other systems, job run logs stored in a database may be
the answer. This allows other systems to access and
report on job status.
An important part of successfully implementing a busy
job run log is to limit logging to inserts. Updates and
deletes should be avoided if possible. Best practice
would be to create a database view that filtered the data
to the last status per process per day (or process run).
The DTstamp macro variable from tip #1 makes a great
process identifier.
Logging Tip #2
Table: job_run_log
View: job_run_log_v
CREATE TABLE job_run_log
( process_id bigint NOT NULL, process_name VARCHAR(100),
status VARCHAR(50), note VARCHAR(255),
rcrd_create_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (process_id, rcrd_create_ts) )
CREATE VIEW job_run_log_v as
select a.* from test.job_run_log a
join (
select process_id, max(rcrd_create_ts) as last_ts
from test.job_run_log
group by 1
) b on a.process_id = b.process_id and a.rcrd_create_ts = b.last_ts
;
Often we need to understand when something
happened at the second level. This is especially true
for long running jobs.
To aid in this effort, we add timestamps to the SAS log
for key events or interactions.
Logging Tip #3
%macro timestamp_it();
/* Note that the format statement can be moved to the settings files for
the job */
proc format;
picture DTstamp
other='%Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);
run;
%put NOTE: %sysfunc(datetime(),DTstamp.);
%mend;
%timestamp_it;
3
MLOGIC – This option is different from MPRINT in that
it displays the logic that is being executed. Therefore,
if you have for loops or conditional statements,
MLOGIC will help understand the execution.
SYMBOLGEN – Have you ever had to include %PUT
statements just to know what the macro variables
resolve to? SYMBOLGEN does that for you. It outputs
the value of macro variables as they are used.
FULLSTIMER – Briefly, FULLSTIMER outputs
performance statistics for each step in a SAS job. This
helps debug long running queries, etc.
Locked datasets can cause problems if there are
potentially multiple processes accessing them. We
have removed this by locking a dataset first, accessing
or updating, and then unlocking. Here are examples of
how this works from PharmaSUG2005.
Tips and Tricks for SAS® Program Automation
Adam Hood
Slalom Consulting
Error Handling Tip #1
There are occasions where missing data can cause a
domino effect of downstream errors. We find it
helpful to check the rows returned by critical queries
so an error can be thrown immediately instead of
downstream. Here is an example macro for just that.
Error Handling Tip #2 System Option Tips
SAS Community Tips – Adding a date and time stamp
to the SAS Log -
http://www.sascommunity.org/wiki/Tips:Adding_a_da
te_and_time_stamp_message_to_the_SAS_Log
The Big Introduction from the Smallest Macro -
http://www2.sas.com/proceedings/sugi31/038-31.pdf
Automating your SAS jobs, Paul Anderson, SGF 2009 -
http://support.sas.com/resources/papers/proceedings
09/184-2009.pdf
Play Nice with Others: Waiting for a Lock on SAS Table,
John Leveille and Jimmy Hunnings, PharmaSUG 2005 -
http://www.lexjansen.com/pharmasug/2005/posters/
po33.pdf
References
%macro check_sql;
%if &sqlobs.=0 %then %do;
%put ERROR: SQL Query returned no rows.;
%end;
%else %do;
%put NOTE: SQL Checked.;
%end;
%mend check_sql;
%macro trylock(member=,timeout=10,retry=1);
%local starttime;
%let starttime = %sysfunc(datetime());
%do %until(&syslckrc <= 0
or %sysevalf(%sysfunc(datetime()) > (&starttime + &timeout)));
%put trying open ...;
data _null_;
dsid = 0;
do until (dsid > 0 or datetime() > (&starttime + &timeout));
dsid = open("&member");
if (dsid = 0) then rc = sleep(&retry);
end;
if (dsid > 0) then rc = close(dsid);
run;
%put trying lock ...;
lock &member;
%put syslckrc=&syslckrc;
%end;
%mend trylock;
Debugging is critical when working with automated
programs. Our approach is to turn on the debugging
options in the settings file for the job. This produces
larger logs, but we overcome this with an aggressive log
retention policy.
There are 4 options that we use to help debug programs.
MPRINT – If you use macros in any significant way, this
will help you debug. MPRINT will print the macro as it is
included in the code.
Sgf15 tips and tricks for sas program automation-final post1

More Related Content

Similar to Sgf15 tips and tricks for sas program automation-final post1

20 Windows Tools Every SysAdmin Should Know
20 Windows Tools Every SysAdmin Should Know20 Windows Tools Every SysAdmin Should Know
20 Windows Tools Every SysAdmin Should KnowPower Admin LLC
 
Welcome Webinar Slides
Welcome Webinar SlidesWelcome Webinar Slides
Welcome Webinar SlidesSumo Logic
 
Habits of Effective SAS Programmers
Habits of Effective SAS ProgrammersHabits of Effective SAS Programmers
Habits of Effective SAS ProgrammersSunil Gupta
 
How Manual Testers Can Break into Automation Without Programming Skills
How Manual Testers Can Break into Automation Without Programming SkillsHow Manual Testers Can Break into Automation Without Programming Skills
How Manual Testers Can Break into Automation Without Programming SkillsRanorex
 
SAP ADMINISTRATION
SAP ADMINISTRATIONSAP ADMINISTRATION
SAP ADMINISTRATIONAly Adel
 
File Processing - Batch Process Execution
File Processing - Batch Process ExecutionFile Processing - Batch Process Execution
File Processing - Batch Process ExecutionAbimael Desales López
 
File Processing - Process Execution Solution
File Processing - Process Execution SolutionFile Processing - Process Execution Solution
File Processing - Process Execution SolutionAbimael Desales López
 
automation process
automation processautomation process
automation processDhiraj Jha
 
Ibm ims tools san ramon oct 2011
Ibm ims tools san ramon oct 2011Ibm ims tools san ramon oct 2011
Ibm ims tools san ramon oct 2011evgeni77
 
How to Create a Runbook: A Guide for Sysadmins & MSPs
How to Create a Runbook: A Guide for Sysadmins & MSPsHow to Create a Runbook: A Guide for Sysadmins & MSPs
How to Create a Runbook: A Guide for Sysadmins & MSPsLizzyManz
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2rowensCap
 
10 best-practices-for-new-robotic-process-automation-rpa-developer-220f7ccdf33
10 best-practices-for-new-robotic-process-automation-rpa-developer-220f7ccdf3310 best-practices-for-new-robotic-process-automation-rpa-developer-220f7ccdf33
10 best-practices-for-new-robotic-process-automation-rpa-developer-220f7ccdf33Srinivas Kannan
 
20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPMcamunda services GmbH
 
Mind the gap - Troopers 2016
Mind the gap  - Troopers 2016Mind the gap  - Troopers 2016
Mind the gap - Troopers 2016Casey Smith
 
Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1Valerii Kravchuk
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaMark Leith
 

Similar to Sgf15 tips and tricks for sas program automation-final post1 (20)

20 Windows Tools Every SysAdmin Should Know
20 Windows Tools Every SysAdmin Should Know20 Windows Tools Every SysAdmin Should Know
20 Windows Tools Every SysAdmin Should Know
 
Welcome Webinar Slides
Welcome Webinar SlidesWelcome Webinar Slides
Welcome Webinar Slides
 
Habits of Effective SAS Programmers
Habits of Effective SAS ProgrammersHabits of Effective SAS Programmers
Habits of Effective SAS Programmers
 
pm1
pm1pm1
pm1
 
How Manual Testers Can Break into Automation Without Programming Skills
How Manual Testers Can Break into Automation Without Programming SkillsHow Manual Testers Can Break into Automation Without Programming Skills
How Manual Testers Can Break into Automation Without Programming Skills
 
Carasik BPM ECM
Carasik BPM ECMCarasik BPM ECM
Carasik BPM ECM
 
SAP ADMINISTRATION
SAP ADMINISTRATIONSAP ADMINISTRATION
SAP ADMINISTRATION
 
File Processing - Batch Process Execution
File Processing - Batch Process ExecutionFile Processing - Batch Process Execution
File Processing - Batch Process Execution
 
File Processing - Process Execution Solution
File Processing - Process Execution SolutionFile Processing - Process Execution Solution
File Processing - Process Execution Solution
 
automation process
automation processautomation process
automation process
 
Ibm ims tools san ramon oct 2011
Ibm ims tools san ramon oct 2011Ibm ims tools san ramon oct 2011
Ibm ims tools san ramon oct 2011
 
How to Create a Runbook: A Guide for Sysadmins & MSPs
How to Create a Runbook: A Guide for Sysadmins & MSPsHow to Create a Runbook: A Guide for Sysadmins & MSPs
How to Create a Runbook: A Guide for Sysadmins & MSPs
 
11i Logs
11i Logs11i Logs
11i Logs
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2
 
10 best-practices-for-new-robotic-process-automation-rpa-developer-220f7ccdf33
10 best-practices-for-new-robotic-process-automation-rpa-developer-220f7ccdf3310 best-practices-for-new-robotic-process-automation-rpa-developer-220f7ccdf33
10 best-practices-for-new-robotic-process-automation-rpa-developer-220f7ccdf33
 
20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM20061122 JBoss-World Experiences with JBoss jBPM
20061122 JBoss-World Experiences with JBoss jBPM
 
Mind the gap - Troopers 2016
Mind the gap  - Troopers 2016Mind the gap  - Troopers 2016
Mind the gap - Troopers 2016
 
RAMP_FINAL_ppt
RAMP_FINAL_pptRAMP_FINAL_ppt
RAMP_FINAL_ppt
 
Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
 

Recently uploaded

Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 

Recently uploaded (20)

Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 

Sgf15 tips and tricks for sas program automation-final post1

  • 1. Tips and Tricks for SAS® Program Automation Adam Hood @ Slalom Consulting
  • 2. 2 Use PROC PRINTTO to put all logs in a designated directory. This will allow any team member to quickly find and troubleshoot problems in processes. All too often teams spend time trying to find the appropriate logs for a given process. To further enhance your log files, add a timestamp for easy sorting and a naming convention for specific process identification. Tips and Tricks for SAS® Program Automation Adam Hood Slalom Consulting Abstract Automating SAS programs can be difficult and result in overcoming unexpected obstacles. Often automation forces us to account for edge case scenarios that we would normally assume won’t be encountered. The goal of this poster is to help programmers overcome the ‘gotcha’s associated with building and troubleshooting automated programs. We will touch on 3 areas: logging, basic error handling, and system options. Logging Tip #1 proc format ; picture myfmt low-high = '%0Y%0m%0d%0H%0M%0S' (datatype = datetime) ; run ; %let DTstamp =%sysfunc(datetime(),myfmt.); proc printto log=“/home/ahood/logs/myprocess_&DTstamp..log” new; Often there are multiple stakeholders for a given automated job. Emails are a great way to let others know when jobs finish. However, if you want a more self- service approach or you want to build dependencies with other systems, job run logs stored in a database may be the answer. This allows other systems to access and report on job status. An important part of successfully implementing a busy job run log is to limit logging to inserts. Updates and deletes should be avoided if possible. Best practice would be to create a database view that filtered the data to the last status per process per day (or process run). The DTstamp macro variable from tip #1 makes a great process identifier. Logging Tip #2 Table: job_run_log View: job_run_log_v CREATE TABLE job_run_log ( process_id bigint NOT NULL, process_name VARCHAR(100), status VARCHAR(50), note VARCHAR(255), rcrd_create_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (process_id, rcrd_create_ts) ) CREATE VIEW job_run_log_v as select a.* from test.job_run_log a join ( select process_id, max(rcrd_create_ts) as last_ts from test.job_run_log group by 1 ) b on a.process_id = b.process_id and a.rcrd_create_ts = b.last_ts ; Often we need to understand when something happened at the second level. This is especially true for long running jobs. To aid in this effort, we add timestamps to the SAS log for key events or interactions. Logging Tip #3 %macro timestamp_it(); /* Note that the format statement can be moved to the settings files for the job */ proc format; picture DTstamp other='%Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime); run; %put NOTE: %sysfunc(datetime(),DTstamp.); %mend; %timestamp_it;
  • 3. 3 MLOGIC – This option is different from MPRINT in that it displays the logic that is being executed. Therefore, if you have for loops or conditional statements, MLOGIC will help understand the execution. SYMBOLGEN – Have you ever had to include %PUT statements just to know what the macro variables resolve to? SYMBOLGEN does that for you. It outputs the value of macro variables as they are used. FULLSTIMER – Briefly, FULLSTIMER outputs performance statistics for each step in a SAS job. This helps debug long running queries, etc. Locked datasets can cause problems if there are potentially multiple processes accessing them. We have removed this by locking a dataset first, accessing or updating, and then unlocking. Here are examples of how this works from PharmaSUG2005. Tips and Tricks for SAS® Program Automation Adam Hood Slalom Consulting Error Handling Tip #1 There are occasions where missing data can cause a domino effect of downstream errors. We find it helpful to check the rows returned by critical queries so an error can be thrown immediately instead of downstream. Here is an example macro for just that. Error Handling Tip #2 System Option Tips SAS Community Tips – Adding a date and time stamp to the SAS Log - http://www.sascommunity.org/wiki/Tips:Adding_a_da te_and_time_stamp_message_to_the_SAS_Log The Big Introduction from the Smallest Macro - http://www2.sas.com/proceedings/sugi31/038-31.pdf Automating your SAS jobs, Paul Anderson, SGF 2009 - http://support.sas.com/resources/papers/proceedings 09/184-2009.pdf Play Nice with Others: Waiting for a Lock on SAS Table, John Leveille and Jimmy Hunnings, PharmaSUG 2005 - http://www.lexjansen.com/pharmasug/2005/posters/ po33.pdf References %macro check_sql; %if &sqlobs.=0 %then %do; %put ERROR: SQL Query returned no rows.; %end; %else %do; %put NOTE: SQL Checked.; %end; %mend check_sql; %macro trylock(member=,timeout=10,retry=1); %local starttime; %let starttime = %sysfunc(datetime()); %do %until(&syslckrc <= 0 or %sysevalf(%sysfunc(datetime()) > (&starttime + &timeout))); %put trying open ...; data _null_; dsid = 0; do until (dsid > 0 or datetime() > (&starttime + &timeout)); dsid = open("&member"); if (dsid = 0) then rc = sleep(&retry); end; if (dsid > 0) then rc = close(dsid); run; %put trying lock ...; lock &member; %put syslckrc=&syslckrc; %end; %mend trylock; Debugging is critical when working with automated programs. Our approach is to turn on the debugging options in the settings file for the job. This produces larger logs, but we overcome this with an aggressive log retention policy. There are 4 options that we use to help debug programs. MPRINT – If you use macros in any significant way, this will help you debug. MPRINT will print the macro as it is included in the code.