BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Suzy_Cat
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

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;

View solution in original post

4 REPLIES 4
Suzy_Cat
Pyrite | Level 9

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;

 

Suzy_Cat
Pyrite | Level 9

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;

 

ErikLund_Jensen
Rhodochrosite | Level 12

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;
Suzy_Cat
Pyrite | Level 9
This is exactly what I wanted to achieve! Thank you sooo much for the help 🙂

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1857 views
  • 2 likes
  • 2 in conversation