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?
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.
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;
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...
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.
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
Proc Scaproc might offer what you're after.
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
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.
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.