Thursday, June 14, 2012

To calculate SAS program run time

Sometimes, I wanted to compare the efficiency between two approaches. I used following codes to get the program execution run-time:
 
%let _sdtm=%sysfunc(datetime());
*** SAS codes ***;
%let _edtm=%sysfunc(datetime());
%let _runtm=%sysfunc(putn(&_edtm - &_sdtm, 12.4));
%put It took &_runtm second to run the program;

It is also very easy to print the date and time:
%put %sysfunc(putn(&_sdtm, datetime20.));

4 comments:

  1. Very useful, I pasted it simply into my progam.

    ReplyDelete
  2. I concur. Thank you for helping random people.

    ReplyDelete
  3. Here is how you can create and embed simple SAS timer into your SAS code: SAS timer - the key to writing efficient SAS code .

    ReplyDelete
  4. Hi there I have multiple macro call to some tasks in one data step. and I need to get the time taken by each of them individually.

    I tried the above code for each of them but it is not giving desired results.
    data _NULL_;
    %let START_TIME=%sysfunc(datetime());
    call execute ('%exesql(sqlstatement='||'truncate table STAGING.&TableName);');
    call execute ('%exesql(sqlstatement="&&InsertStmt");');
    %let END_TIME=%sysfunc(datetime());
    call execute('%Audit('||'&START_TIME'||','||'&END_TIME'||','||'&TableName'||',Load_Sub_Claim_Feed,Y);');

    %let START_TIME=%sysfunc(datetime());
    call execute ('%exesql(sqlstatement='||'truncate table STAGING.&TableName);');
    call execute ('%exesql(sqlstatement="&&InsertStmt");');
    %let END_TIME=%sysfunc(datetime());
    call execute('%Audit('||'&START_TIME'||','||'&END_TIME'||','||'&TableName'||',Load_Sub_Claim_Feed,Y);');
    call execute ('%exesql(sqlstatement='||'truncate table STAGING.&TableName);');
    call execute ('%exesql(sqlstatement="&&InsertStmt");');
    run;

    ReplyDelete