In daily data management with SAS©, it is often necessary to duplicate an existing table. But what if you only want the "skeleton" of the table (the variables, formats, types) without importing the thousands or millions of rows it contains?
Whether you need to create an empty template for new data entry or to initialize an archive table, here is the simplest and most effective method for copying a table structure from one library to another.
Why does this work?
To understand this trick, you need to look under the hood of the SAS© engine:
The SET statement: At compile time, SAS© reads the descriptor of the source table (prod.ventes_2023). It prepares the "Program Data Vector" (PDV) with all the variables and their attributes. The structure is thus ready.
The STOP statement: Normally, the DATA step works like an implicit loop that reads rows one by one. The STOP statement forces the immediate termination of the DATA step before the first row of data is even loaded into the PDV and written to the output table.
It is this immediate interruption that allows the structure (defined at compilation) to be saved without ever processing the data (execution).
The next time you need an empty table template, remember: a simple STOP is all it takes!