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 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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