How do I put a time stamp onto a sas database? I want the person whom I will be sending my database to to see when the database was output.
@K_S Just to clarify what others already said.
SAS tables are nothing else than files on the file system with an extension of .sas7bdat
A SAS file contains internally some metadata header information and then the data. In the header information there is also the datetime when the file has been created. That's what you get when running Proc Contents.
If you want to log the time per data row (and not the whole file) then you need to create and populate a variable which holds this information. That's the proposed solution using the data step with the datetime() function.
And last but not least: Most of the time SAS tables (.sas7bdat files) get fully recreated. If using SQL or a SAS data step modify or update statement then you can also update a SAS table in place and though file creation and file modification date might differ.
Sample code:
/* create a new table */
data test;
set sashelp.class;
run;
/* create a new table by replacing a same named source table */
/* -> because it's a new table creation and modification DateTime will be the same */
data test;
set test;
run;
/** modify an existing table. Creation and modification DateTime will differ **/
/* wait a second */
data _null_;
call sleep(1,1);
run;
/* update (modify) table in place (=not re-creating it) */
proc sql;
update test
set name='ABC'
where name='Alfred'
;
quit;
/* report on table metadata */
proc contents data=test;
run;
I will have to look up what you mean. I am not new to SAS but there are still many many many things I don't know/understand.
@K_S Just to clarify what others already said.
SAS tables are nothing else than files on the file system with an extension of .sas7bdat
A SAS file contains internally some metadata header information and then the data. In the header information there is also the datetime when the file has been created. That's what you get when running Proc Contents.
If you want to log the time per data row (and not the whole file) then you need to create and populate a variable which holds this information. That's the proposed solution using the data step with the datetime() function.
And last but not least: Most of the time SAS tables (.sas7bdat files) get fully recreated. If using SQL or a SAS data step modify or update statement then you can also update a SAS table in place and though file creation and file modification date might differ.
Sample code:
/* create a new table */
data test;
set sashelp.class;
run;
/* create a new table by replacing a same named source table */
/* -> because it's a new table creation and modification DateTime will be the same */
data test;
set test;
run;
/** modify an existing table. Creation and modification DateTime will differ **/
/* wait a second */
data _null_;
call sleep(1,1);
run;
/* update (modify) table in place (=not re-creating it) */
proc sql;
update test
set name='ABC'
where name='Alfred'
;
quit;
/* report on table metadata */
proc contents data=test;
run;
Usually external databases timestamp table rows as you could be updating rows at different times. If you want to use this methodology in SAS apply the DATETIME function to a new variable in your dataset in a DATA step:
data want;
set have;
timestamp = datetime();
format timestamp datetime22;
run;
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.