Hello
Lets say that I run a SAS program that create multiple data sets .
I want to know how long time it take to create each data set and have this information in a data sets.
This data set will have following columns:
A-Data set name (The data set that we create)
B-date+time start execute the creation of the data set
C-date+time finish execute the creation of the data set
D-Time in minutes or seconds to create the data set(difference between C and B)
Please note that id there are other procedures that dont create data set (such as proc print/proc means noprint and so on ) then no need to include them in this information
1)
proc scaproc; record 'c:\temp\temp.txt'; run; data x; set sashelp.demographics; if ISONAME in ('JAPAN' 'CHINA'); run; proc scaproc; write; run;
In the file c:\temp\temp.txt, you need to pull up the date value of starting and ending .
/* JOBSPLIT: JOBSTARTTIME 12APR2025:14:47:20.78 */ /* JOBSPLIT: TASKSTARTTIME 12APR2025:14:47:20.79 */ /* JOBSPLIT: DATASET INPUT SEQ #C00007.DEMOGRAPHICS.DATA */ /* JOBSPLIT: LIBNAME #C00007 V9 'C:\Program Files\SASHome\SASFoundation\9.4\graph\sashelp' */ /* JOBSPLIT: CONCATMEM #C00007 SASHELP */ /* JOBSPLIT: LIBNAME SASHELP V9 '( 'C:\Program Files\SASHome\SASFoundation\9.4\nls\zh\SASCFG' 'C:\Program Files\SASHome\SASFoundation\9.4\nls\zh\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\core\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\aacomp\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\cas\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\cmp\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\genetics\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\graph\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\iml\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\mlearning\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\spdsclient\sashelp' 'C:\Program Files\SASHome\SASFoundation\9.4\stat\sashelp' )' */ /* JOBSPLIT: DATASET OUTPUT SEQ WORK.X.DATA */ /* JOBSPLIT: LIBNAME WORK V9 'C:\Users\XIAKES~1\AppData\Local\Temp\SAS Temporary Files\_TD13460_LAPTOP-3FUEBKR4_' */ /* JOBSPLIT: FILE OUTPUT c:\temp\temp.txt */ /* JOBSPLIT: ELAPSED 44 */ /* JOBSPLIT: SYSSCP WIN */ /* JOBSPLIT: PROCNAME DATASTEP */ /* JOBSPLIT: STEP SOURCE FOLLOWS */ data x; set sashelp.demographics; if ISONAME in ('JAPAN' 'CHINA'); run; /* JOBSPLIT: JOBENDTIME 12APR2025:14:47:20.84 */ /* JOBSPLIT: END */
2)
Or you could hard code to get this interval of time:
%let start=%sysfunc(datetime());
data x;
set sashelp.demographics;
if ISONAME in ('JAPAN' 'CHINA');
call sleep(2,1);
run;
%let end=%sysfunc(datetime());
%let interval=%sysfunc(putn(%sysevalf(&end. - &start.), time14.2));
%put &interval.;
123 %let end=%sysfunc(datetime()); 124 125 %let interval=%sysfunc(putn(%sysevalf(&end. - &start.), time14.2)); 126 %put &interval.; 0:00:04.08
3)Or using PROC PRINTTO to save your log into a new file and pull out these start and end date:
proc printto log='c:\temp\temp.txt' new;run;
data x;
set sashelp.demographics;
if ISONAME in ('JAPAN' 'CHINA');
call sleep(2,1);
run;
proc printto;run;
NOTE: “PROCEDURE PRINTTO”所用时间(总处理时间): 实际时间 0.00 秒 CPU 时间 0.00 秒 14 15 data x; 16 set sashelp.demographics; 17 if ISONAME in ('JAPAN' 'CHINA'); 18 call sleep(2,1); 19 run; NOTE: 从数据集 SASHELP.DEMOGRAPHICS. 读取了 197 个观测 NOTE: 数据集 WORK.X 有 2 个观测和 18 个变量。 NOTE: “DATA 语句”所用时间(总处理时间): 实际时间 4.03 秒 CPU 时间 0.14 秒 20 21 proc printto;run;
I found this to be an interesting exercise and wanted to give it a whirl. I'm working in a UNIX environment so I wondered what happened with the file information and compare that to the SAS Data Set metadata information.
I have a macro called %UNIX_STAT that runs a stat command on a given file and writes the results to a named SAS data set. Details include atime (last access date-time), mtime (last modified date-time), and ctime (last change date-time). I rename those to ACCESS_DATE, MODIFY_DATE, and CHANGE_DATE.
The results were interesting. In my case, I noticed that the unix file data matched the START TIME of the data step, where the SAS metadata for CRDTE and MODTE marked the END TIME of the data step. One could use this information to develop further the process of recording and measuring start time, end time, and run time of a data step.
However, those times would only reflect "real time" and not necessarily point to efficiency in a shared environment: cpu usage, swap, and other measures could come in to play.
The results on a windows or other environment may vary.
Here's my test:
31 *test data set ;
32 %put DATETIME=%sysfunc(datetime(), datetime.) ;
DATETIME=12APR25:23:39:36
33 data mydata ;
34 do i = 1 to 10 ;
35 sleep = sleep (5, 1) ;
36 output ;
37 end ;
38 run ;
NOTE: The data set WORK.MYDATA has 10 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 50.02 seconds
cpu time 0.02 seconds
39 %put DATETIME=%sysfunc(datetime(), datetime.) ;
DATETIME=12APR25:23:40:26
40
41 %macro datatimer (data) ;
42 %local data dsid crdte modte rc ;
43 %let dsid = %sysfunc(open(&data)) ;
44
45 %if &dsid %then %do ;
46 %let crdte = %sysfunc(attrn(&dsid, crdte), datetime.) ;
47 %let modte = %sysfunc(attrn(&dsid, modte), datetime.) ;
2 The SAS System 22:19 Saturday, April 12, 2025
48 %let rc = %sysfunc(close(&dsid)) ;
49 %end ;
50
51 %put &=crdte &=modte ;
52 %mend datatimer ;
53
54 %datatimer (mydata) ;
CRDTE=12APR25:23:39:36 MODTE=12APR25:23:39:36
55
56 %unix_stat (file=%sysfunc(pathname(work))/mydata.sas7bdat, out=stat) ;
NOTE: The data set WORK.STAT has 1 observations and 13 variables.
NOTE: MACRO %UNIX_STAT used:
real time 00:00.14
cpu time unknown
57
58 data _null_ ;
59 set stat ;
60 put access_date= modify_date= change_date= ;
61 run ;
access_date=12APR25:23:40:26 modify_date=12APR25:23:40:26 change_date=12APR25:23:40:26
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.