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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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