Date: Wed, 4 Dec 2002 15:16:30 -0500
Reply-To: "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Subject: tip macro function CLOCK V2
Content-Type: text/plain
I get by with a lotta help from SAS-L.
thanx to Pete Lund and Peter Crawford for critique
Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov
"Nothing is particularly hard
if you divide it into small jobs."
- Henry Ford, Industrialist
/*CLOCK macro function returns time or elapsed time
USAGE:
%CLOCK();
%PUT STARTED:%CLOCK(TIME);
%LET TIME0 = %CLOCK(START);
%LET TIME1 = %CLOCK(START);
*proc;
%PUT TIME1 = %CLOCK(&TIME1.) of proc;
%PUT TIME0 = %CLOCK(&TIME0.) of job;
%PUT ENDED@: %CLOCK(TIME);
/* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
%macro CLOCK
(ACTION/* in (? HELP START TIME &MVAR.) */
,FMT_TIME = time12.3
,FMT_DATE = datetime22.3
)/des = "&SYSDATE. &SYSUSERID. " /*SASMACRO.cat.description*/
/*store /*store & compile must have options mStored SASmStore=libref*/
;/*-------------------------------------------------------------------**
RJF2 02Nov22
1234567890123456789012
04DEC2002:14:19:16.051
RJF2 02Dec04 polishing; NOTE: passing value, not reference
> From: Pete Lund [mailto:pete.lund@nwcsr.com]
> Subject: RE: tip macro function CLOCK
> If you change your %eval to %sysevalf you can get the
> fractional seconds - assuming you also take out the
> recalculation of &now and change the output format to time12.2.
no need to substring NOW
%LET NOW = %substr( &NOW.,1
,%index(&NOW.,.)-1);
%ELSE %DO;%sysfunc(putn(%eval( &NOW. - &ACTION.),time8.0)) %END;
> From: Peter Crawford [mailto:peter.crawford@db.com]
uses range function: note different FMT_TIME.
%let p = %sysfunc( range( "&n"dt, "&&&from"dt ), time11.2 );
/*...................................................................*/
%IF &ACTION. eq
or &ACTION. eq ?
or &ACTION. eq HELP %THEN %DO;;%PUT CLOCK usage:;
%PUT %nrstr(%PUT START:%CLOCK(TIME ););
%PUT %nrstr(%LET MVAR =%CLOCK(START););
%PUT %nrstr(%PUT USED :%CLOCK(&MVAR););
%PUT %nrstr(%PUT END :%CLOCK(TIME ););
%GOTO EXIT; %END;
%ELSE %IF &ACTION. eq START %THEN %DO;%sysfunc(datetime() )%END;
%ELSE %IF &ACTION. eq TIME %THEN %DO;%sysfunc(datetime()
,&FMT_DATE.)%END;
%ELSE %DO;%sysfunc(putn(%sysevalf(
%sysfunc(datetime() )
- &ACTION.),&FMT_TIME.))%END;
%*........................................................; %EXIT:%MEND;
;/* TEST DATA ***********************to enable end this line w/slash **
%MACRO SOMETIME(N);DATA _NULL_;do I = 1 to 1E&N.;end;stop;run;%MEND;
%CLOCK();
%PUT STARTED:%CLOCK(TIME);
%LET TIME0 = %CLOCK(START);
%LET TIME1 = %CLOCK(START);
%SOMETIME(7);
%PUT TIME1 = %CLOCK(&TIME1.) of proc;
%PUT TIME0 = %CLOCK(&TIME0.) of job;
%PUT ENDED@: %CLOCK(TIME);
;/*...................................................................*/
|