SAS9

SAS Tutorial: How to Measure Total Execution Time

Simon 14 Aufrufe

When trying to optimize SAS© processes or monitor the performance of a production chain, the default information provided in the "Log" window can be frustrating.

By default, SAS© displays performance statistics (real time, CPU time, memory) after each step (DATA step or PROC).

1NOTE: DATA statement used (Total process time):
2 real time 0.01 seconds
3 user cpu time 0.00 seconds
4 system cpu time 0.01 seconds

The recurring question is: How to get the cumulative statistics for an entire program containing dozens of consecutive steps?

Here are the three main methods, from the simplest to the most advanced.

Method 1: Batch Mode Execution (The Native Method)

This is the most direct solution if you do not need interactivity. When you run a SAS© program in Batch mode (via the command line or a scheduler), SAS© slightly changes its logging behavior.

At the very end of the generated .log file, SAS© automatically inserts a statistical summary of the entire session.

How to do it: Instead of opening SAS© Enterprise Guide or SAS© Base interactively:

  1. Run your program via the system executable (e.g., sas©.exe -sysin my_program.sas©).

  2. Open the resulting log file (my_program.log).

  3. Go to the very bottom of the file to find the "SAS© Session Statistics" block.

Method 2: Log Scraping (Log Analysis)

If you need to log these performances (for example, to compare the execution speed of a process day after day), manually reading the log is not enough. The solution recommended by experts is to create a small program that "reads" your logs.

The idea is to use SAS© to read its own text output files.

The concept:

  1. Enable the FULLSTIMER option at the beginning of your main program to get maximum detail.

  2. Once the program is finished, run a "scraping" script that reads the .log file.

  3. Look for lines starting with "real time" or "cpu time".

  4. Extract the numerical values and sum them up.

This is the ideal method for building performance monitoring dashboards.

Method 3: The ARM Subsystem (The Pro Method)

For more complex needs (e.g., measuring the time of a specific code section without including initialization), we suggest using ARM (Application Response Measurement).

ARM is an industry standard for performance measurement, integrated into SAS© via specific macros. It allows you to define custom "start" and "end" transactions.

Conceptual Example:

1/* Initialisation du système ARM */
2%let _armagent=1;
3%arm_init(appname="MonApplicationCritique");
4 
5/* Début du chronomètre pour une section précise */
6%arm_start(name="Etape_Importation");
7 
8 /* ... Votre code lourd ici ... */
9 DATA work.test; SET SOURCE.big_data; RUN;
10 
11/* Fin du chronomètre et enregistrement du log */
12%arm_stop(name="Etape_Importation");
13 
14%arm_end();

The results are then stored cleanly in a dedicated log file or table, facilitating precise analysis without having to parse raw text.

Quick Alternative: Timestamps

If you don't need CPU/Memory precision but just the real duration ("Wall clock time") for a block of code, you can simply use macro variables at the beginning and end of your script:

1/* Début du chronomètre */
2%let start_time = %sysfunc(datetime());
3 
4 /* ... Vos multiples PROC et DATA steps ... */
5 PROC SORT DATA=sashelp.class out=class; BY age; RUN;
6 DATA _null_; SET class; RUN;
7 
8/* Fin et calcul */
9%let end_time = %sysfunc(datetime());
10%let duree = %sysfunc(putn(%sysevalf(&end_time - &start_time), time8.));
11 
12%put NOTE: Total processing time: &duree;