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.
%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;
%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
@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;
%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;
Note that in
%let StartTime = %sysfunc(datetime(), datetime20.); data example; st = input("&StartTime.",datetime20.); st2 = "&StartTime."dt; run;
ST and ST2 are identical.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.