DATA Step, Macro, Functions and more

output the timing of each data step into a table

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

output the timing of each data step into a table

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?


Accepted Solutions
Solution
a week ago
Frequent Contributor
Posts: 112

Re: output the timing of each data step into a table

@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


All Replies
Frequent Contributor
Posts: 111

Re: output the timing of each data step into a table

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;

 

Frequent Contributor
Posts: 123

Re: output the timing of each data step into a table

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

Solution
a week ago
Frequent Contributor
Posts: 112

Re: output the timing of each data step into a table

@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.  

Respected Advisor
Posts: 4,802

Re: output the timing of each data step into a table

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 83 views
  • 3 likes
  • 5 in conversation