"Time flies like an arrow; fruit flies like a banana"
Often when writing code it's important to know how long it will take to run. This can be very useful when creating loops that need to be repeated hundreds of times or when working out which bits of code are slowing everything else down.
The following code will work out how long something takes to run and output the time into the log:
%let tic = %sysfunc(time(),8.);
*Insert code here*
%let toc = %sysfunc(time(),8.);
%put Total Time %sysfunc(putn(%eval(&toc-&tic)
The code works by storing the system times into the macro variables 'tic' and 'toc'. The difference between the two will tell you how long the code took to run. Here the 'Total Time' taken is printed into the log, but it can just as easily be saved into a data set for later viewing.
Mark Meat.
No comments:
Post a Comment