Hi,
suppose that I have 3 tables: A,B,C.
What I would like to do is for each table to add a new column called "table" and the value in each row of this new column for each table is the name of the table itself.
So table A will have a new column "table" with values a, a, a, a, ....
table B will have a new column named "table" with values b,b,b,...
And so on.
Thank you !
Why would you want to do this?
Hi Reeza,
I have many tables of stocks. Each table is named after the stock and has two columns: "date" and "daily price".
In order to perform my analysis I need to merge all the tables together into one table, but since there is no indicator which date and price is for which stock, the analysis won't be possible.
Thank you!
Thank you Reeza,
I got the answer that I needed!!!
Indsname happens to be a very useful function, I didn't even know it existed.
Thank you again!!!
The solution above is what i really wanted
Take advantage of the INDSNAME option to automatically grab the table name.
I'm really curious for the use case of adding this variable, besides when you are setting multiple tables together and even then you can use the INDSNAME option directly.
%macro add_name(dsn); data &dsn; set &dsn indsname=source; Table = scan(source, 2); run; %mend; %add_name(tableA); %add_name(TableB)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.