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

This is probably easy.....but I can't figure it out.  At the start I have:

 

%let StartTime = %sysfunc(datetime(), datetime20.);

 

do a lot of programming

at the end:

 

%let EndTime = %sysfunc(datetime(), datetime20.);

 

I need to be able to save to one dataset (so I can send to excel later if need) the StartTime, EndTime and difference (time taken). So the final dataset would be:

 

Start_Time        whatever value

End_Time         whatever value

Take_Taken      whatever value

 

Again, probably easy....but sometimes the easy is troublesome.

1 ACCEPTED SOLUTION

Accepted Solutions
r_behata
Barite | Level 11
%let StartTime = %sysfunc(datetime(), datetime20.);

 
data _null_;
	tmp_=sleep(1000);
run;
 

%let EndTime = %sysfunc(datetime(), datetime20.);

%put &StartTime &EndTime;

data gettime;
format StartTime EndTime datetime20. Elapsed_time best12.;
	StartTime=input("&StartTime",datetime20.);
	EndTime=input("&EndTime",datetime20.);
	Elapsed_time=(StartTime - EndTime)/60;
run;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20
%let start=%sysfunc(datetime());

%let end=%sysfunc(datetime());
%let time_taken=%sysfunc(intck(dthour,&start,&end));
%put &time_taken;

data time_taken;
start=&start;
end=&end;
time_taken=&time_taken;
run;

You can switch to minutes, hours, days, weeks or whatever you want in the first argument where i used dthour

%sysfunc(intck(dthour,&start,&end));

 So bascially Intck calculates the time interval 

ballardw
Super User

@BCNAV wrote:

This is probably easy.....but I can't figure it out.  At the start I have:

 

%let StartTime = %sysfunc(datetime(), datetime20.);

 

do a lot of programming

at the end:

 

%let EndTime = %sysfunc(datetime(), datetime20.);

 

I need to be able to save to one dataset (so I can send to excel later if need) the StartTime, EndTime and difference (time taken). So the final dataset would be:

 

Start_Time        whatever value

End_Time         whatever value

Take_Taken      whatever value

 

Again, probably easy....but sometimes the easy is troublesome.


One way if you want CHARACTER values:

 

data times;
   start_time = "&startime.";
   end_time = "&endtime.";
run;

If you want actual date time values then either do not apply the format when creating the variable and use

 

start_time=&startime.;

or if you need the formatted values elsewhere in your code but want the actual datetime value:

data times;
   start_time = "&startime."dt;
   end_time = "&endtime."dt;
   format start_time end_time datetime20.;
run;
r_behata
Barite | Level 11
%let StartTime = %sysfunc(datetime(), datetime20.);

 
data _null_;
	tmp_=sleep(1000);
run;
 

%let EndTime = %sysfunc(datetime(), datetime20.);

%put &StartTime &EndTime;

data gettime;
format StartTime EndTime datetime20. Elapsed_time best12.;
	StartTime=input("&StartTime",datetime20.);
	EndTime=input("&EndTime",datetime20.);
	Elapsed_time=(StartTime - EndTime)/60;
run;
ballardw
Super User

Note that in

%let StartTime = %sysfunc(datetime(), datetime20.);

data example;
    st = input("&StartTime.",datetime20.);
    st2 = "&StartTime."dt;
run;

ST and ST2 are identical.

 

Reeza
Super User

Something like this?

 

proc sql;
create table master_process_time
(Entry char(32),
StartTime num format=datetime22.4,
EndTime num format=datetime22.4,
duration num format=32.4,
recordTime num format=datetime22.4);
quit;

%global startTime endTime;

%macro startTiming();

%let startTime = %sysfunc(datetime());

%mend startTiming;

%macro endTiming(entry=);

%let endTime = %sysfunc(datetime());

proc sql;
insert into master_process_time
values("&Entry", &startTime, &endTime,   %sysevalf(&endTime - &startTime), %sysfunc(datetime()) );
quit;

%mend;


%startTiming();

proc means data=sashelp.class;
run;

%endTiming(entry=ClassMeans);


%startTiming();

proc tabulate data=sashelp.cars;
class origin make;
var mpg_city mpg_highway;
table origin * make, mpg_city*(mean median N) mpg_highway*(mean median n);
run;

%endTiming(entry=TabulateCars);



@BCNAV wrote:

This is probably easy.....but I can't figure it out.  At the start I have:

 

%let StartTime = %sysfunc(datetime(), datetime20.);

 

do a lot of programming

at the end:

 

%let EndTime = %sysfunc(datetime(), datetime20.);

 

I need to be able to save to one dataset (so I can send to excel later if need) the StartTime, EndTime and difference (time taken). So the final dataset would be:

 

Start_Time        whatever value

End_Time         whatever value

Take_Taken      whatever value

 

Again, probably easy....but sometimes the easy is troublesome.


 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 3786 views
  • 1 like
  • 5 in conversation