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

Hi Everyone,

 

I would like to know, how do i create timestamp variable capturing execution start date and time and execution end date and time in sas dataset.

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
dcruik
Lapis Lazuli | Level 10

Are you wanting to put the date and time the program executes and finishes into a data set, or are you wanting to just put the date and time to the log at the beginning of the run and again at the end?  You can do either, although if you put it into the data set it will be there for every observation.  You could do somehting like the following:

 

data final;
set have;
format StartDate mmddyy10. StartTime time10.;
StartDate=date();
StartTime=time();
run;

/*** Other program code ***/

data final;
set final;
format EndDate mmddyy10. EndTime time10.;
EndDate=date();
EndTime=time();
run;

Otherwise, you could always print the date and time to the log once the program begins execution and again when it completes.  That would be like the following:

 

data _NULL_;
put "====================================";
put "Start Date: %sysfunc(date(),worddate.)";
put "Start Time: %sysfunc(time(),time.)";
put "====================================";
run;

/*** Other program code ***/

data _NULL_;
put "====================================";
put "End Date: %sysfunc(date(),worddate.)";
put "End Time: %sysfunc(time(),time.)";
put "====================================";
run;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

The DATETIME() function will return the current datetime (aka timestamp) value.

Not sure how you want to use that but you could store it in macro variable using 

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

 

dcruik
Lapis Lazuli | Level 10

Are you wanting to put the date and time the program executes and finishes into a data set, or are you wanting to just put the date and time to the log at the beginning of the run and again at the end?  You can do either, although if you put it into the data set it will be there for every observation.  You could do somehting like the following:

 

data final;
set have;
format StartDate mmddyy10. StartTime time10.;
StartDate=date();
StartTime=time();
run;

/*** Other program code ***/

data final;
set final;
format EndDate mmddyy10. EndTime time10.;
EndDate=date();
EndTime=time();
run;

Otherwise, you could always print the date and time to the log once the program begins execution and again when it completes.  That would be like the following:

 

data _NULL_;
put "====================================";
put "Start Date: %sysfunc(date(),worddate.)";
put "Start Time: %sysfunc(time(),time.)";
put "====================================";
run;

/*** Other program code ***/

data _NULL_;
put "====================================";
put "End Date: %sysfunc(date(),worddate.)";
put "End Time: %sysfunc(time(),time.)";
put "====================================";
run;
dkanand86
Calcite | Level 5

Thanks!

 

Your code solution will help in:

1. creating timestamp in dataset

2. creating timestamp in log

 

Regards

dkanand86
Calcite | Level 5

One more thing, please can you provide solution for date time together instead of date and time seperately.

 

dcruik
Lapis Lazuli | Level 10

Just use the datetime() instead of date() and time().  Like this:

 

data final;
set have;
format StartDateTime datetime20.;
StartDateTime=datetime();
run;

/*** Other program code ***/

data final;
set final;
format EndDateTime datetime20.;
EndDateTime=datetime();
run;

Or if you're printing to the log, like this:

 

data _NULL_;
put "=============================================";
put "Start Date & Time: %sysfunc(datetime(),datetime.)";
put "=============================================";
run;

/*** Other program code ***/

data _NULL_;
put "=============================================";
put "End Date & Time: %sysfunc(datetime(),datetime.)";
put "=============================================";
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 41589 views
  • 2 likes
  • 3 in conversation