Hi , I need count the duration for how long it take the project to run and show the result in the format "2hr30min" or "2h30m" or "2.5Hr" if the project completed in 2.5 hours. However, I could not figure out how to make the result correctly showing as how long it took the project to run. Can anyone give me a hand?
Thanks.
%let STARTTIME =%sysfunc(time());
data want;
STARTTIME=&STARTTIME;
EndTIME=&STARTTIME+9000;
Duration=&EndTIME-&STARTTIME;
format STARTTIME EndTIME time. Duration $?.;
run;
Hi @Suzy_Cat
You could get your duration time with less effort by using the hour format. Here is a code snippet with the code in a data step and the same code in macro language without a data step
%let STARTTIME =%sysfunc(time());
* Project running...;
* Data step;
data test;
DURATION = put(time()-&STARTTIME,hour5.2)||'Hr';
put DURATION=;
run;
* Macro code;
%let DURATION = %sysfunc(putn(%sysevalf(%sysfunc(time())-&STARTTIME),hour5.2))Hr;
%put &=DURATION;
getting closer....
data test;
STARTTIME=&STARTTIME;
EndTIME=&STARTTIME+9000;
Duration=&EndTIME-&STARTTIME;
minute=INTCK('minute',STARTTIME,EndTIME );
hour=mod(minute/60,60);
format STARTTIME EndTIME time.;
run;
Looks like I got there successfully...
%let STARTTIME =%sysfunc(time());
data want;
STARTTIME=&STARTTIME;
EndTIME=&STARTTIME+12400;
Duration=&EndTIME-&STARTTIME;
minute=INTCK('minute',STARTTIME,EndTIME );
hour=mod(minute/60,60);
dur=put(hour,4.1)!!"Hr";
format STARTTIME EndTIME time.;
run;
Hi @Suzy_Cat
You could get your duration time with less effort by using the hour format. Here is a code snippet with the code in a data step and the same code in macro language without a data step
%let STARTTIME =%sysfunc(time());
* Project running...;
* Data step;
data test;
DURATION = put(time()-&STARTTIME,hour5.2)||'Hr';
put DURATION=;
run;
* Macro code;
%let DURATION = %sysfunc(putn(%sysevalf(%sysfunc(time())-&STARTTIME),hour5.2))Hr;
%put &=DURATION;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.