Print table names into a column

Accepted Solution Solved
Reply
Regular Contributor
Posts: 212
Accepted Solution

Print table names into a column

Hi,

I need to get the table names into a column, but the trickie part is that i need to associate the table names that are in the set statement.

data test;

set test1

       test2

       test3;

/*something like, if comes from test1 then varnew = test1*/

;

I've tried to you dictionary tables but i don't know how to correlate them.

Thank you

Rodrigo Dartibali Elias


Accepted Solutions
Solution
‎08-13-2015 04:47 PM
Super User
Posts: 11,343

Re: Print table names into a column

Posted in reply to DartibaliRodrigo

You maybe should provide a brief example of your input data and what you expect for output.

If you want the name of the input data set contributing the current record then the option INDSNAME.

data test;

length

set test1

       test2

       test3

          INDSNAME=TEMPNAME;

     ColumnVar = Tempname;  /* the variable created by INDSNAME is temporary so assign it to another variable*/

;

run;

You may need to set columnvar and tempname to a length long enough to hold the longest name likely to use.

View solution in original post


All Replies
Occasional Contributor P_2
Occasional Contributor
Posts: 10

Re: Print table names into a column

Posted in reply to DartibaliRodrigo

Just create a variable in each table that identifies where it comes from:

data test1;

set test1;

var = 1;

run;

data test2;

set test2;

var = 2;

run;

data test3;

set test3;

var = 3;

run;

data test;

set test1

       test2

       test3;

if var = 1 then do;

varnew = test1;

end;

run;

Solution
‎08-13-2015 04:47 PM
Super User
Posts: 11,343

Re: Print table names into a column

Posted in reply to DartibaliRodrigo

You maybe should provide a brief example of your input data and what you expect for output.

If you want the name of the input data set contributing the current record then the option INDSNAME.

data test;

length

set test1

       test2

       test3

          INDSNAME=TEMPNAME;

     ColumnVar = Tempname;  /* the variable created by INDSNAME is temporary so assign it to another variable*/

;

run;

You may need to set columnvar and tempname to a length long enough to hold the longest name likely to use.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 188 views
  • 0 likes
  • 3 in conversation