sasdatastep

How to get current table name inside sas data step?


I need to join some tables and create a new column with some mark to indicate the table that data came from.

I have tbl_202101, tbl_202102 ... tbl_202109. I need to join all, adding a new column table_origin, for example, indicating the respective table.

DATA FINAL_TABLE;
SET TBL_202101 - TBL_202109;

/* Here I don't know how to identify the current table */
table_origin = CASE 
WHEN *CURRENT TABLE* = TBL_202101 THEN 202101
WHEN *CURRENT TABLE* = TBL_202102 THEN 202102 
AND GO ON...

RUN;

How could I do it?


Solution

  • Set statement option

        INDSNAME=variable
         
        creates and names a variable that stores the name of the SAS data set
    from which the current observation is read. The stored name can be a data
    set name or a physical name. The physical name is the name by which the
    operating environment recognizes the file.