BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pangea17
Quartz | Level 8

Is there a way to automatically output the timing of each step run in sas code? I know the log will show the elapsed real time/cpu time, but is there a way to combine all of that into a table of sorts for the entirety of the code?

1 ACCEPTED SOLUTION

Accepted Solutions
hashman
Ammonite | Level 13

@pangea17:

 

In the beginning of the program, set:

%let N = 0 ;

Then, precede each step with this statement:

%let t = %sysfunc (datetime()) ;

and follow each step with these statements:

%let N = %eval (&N + 1) ;                 
%let time&N = %sysevalf (%sysfunc (datetime()) - &t) ;

Finally, at the very end of the entire program, run:

data timing ;                                
  do step_no = 1 to &N ;                     
    time = symgetn (cats ("time", step_no)) ;
    output ;                                 
  end ;                                      
run ;                                        

 and you'll get the table you want, with each step number juxtaposed with its timing. You can enhance and augment this with other info, for example, using automatic macro variables in a number of ways depending on your needs.

 

Paul D.  

View solution in original post

7 REPLIES 7
cau83
Pyrite | Level 9

Before you do what I say below, read through the options for SAS logs. I am not aware of how to do this but it may be possible to reference it somehow.

That being said, you can use this code to write your log out to a text file. Then you can read that back in and parse it. Read in each line as a record, in one giant column. Search for those phrases that precede run time numbers you want; only keep those records; and then use character functions to extract the times into a column that you can ultimately convert to numeric.

PROC PRINTTO log="your-file.txt";
run;

 

SuzanneDorinski
Lapis Lazuli | Level 10

Sample 34301: Parse SAS® logs to extract performance and timing information might do what you want.  The sample includes the PASSINFO and the LOGPARSE macros.  

 

There's also a SUGI 30 paper about it by Michael Raithel of Westat:  Programmatically Measure SAS® Application Performance On Any Computer Platform With the New LOGPARSE... 

hashman
Ammonite | Level 13

@pangea17:

 

In the beginning of the program, set:

%let N = 0 ;

Then, precede each step with this statement:

%let t = %sysfunc (datetime()) ;

and follow each step with these statements:

%let N = %eval (&N + 1) ;                 
%let time&N = %sysevalf (%sysfunc (datetime()) - &t) ;

Finally, at the very end of the entire program, run:

data timing ;                                
  do step_no = 1 to &N ;                     
    time = symgetn (cats ("time", step_no)) ;
    output ;                                 
  end ;                                      
run ;                                        

 and you'll get the table you want, with each step number juxtaposed with its timing. You can enhance and augment this with other info, for example, using automatic macro variables in a number of ways depending on your needs.

 

Paul D.  

damiankowalik
Calcite | Level 5

Hi, 

do you have an idea how instead of number of step that was just computed could I retrieve the name of the input and the output table from each of step combined with the time of its execution?

 

Regard

damiankowalik
Calcite | Level 5

Yes, that helps a lot! Thank you. Is there a way to put that information into a table? I am working on a kind of network analysis and that is why I would benefit from tabular output.

 

Best regards

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 5762 views
  • 3 likes
  • 6 in conversation