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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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;

Patrick_0-1629288855970.png

 

 

 

View solution in original post

6 REPLIES 6
Reeza
Super User
It's included as part of the metadata of the data set is it not?
Did you check the sashelp.vtable data set and the date modified/created fields?
K_S
Obsidian | Level 7 K_S
Obsidian | Level 7

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.

Patrick
Opal | Level 21

@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;

Patrick_0-1629288855970.png

 

 

 

SASKiwi
PROC Star

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;
ChrisNZ
Tourmaline | Level 20
All SAS datasets are time stamped. Use proc contents to see this.

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!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1562 views
  • 3 likes
  • 5 in conversation