02-17-2015 02:34 PM
I am trying to join two tables based on the columnValue obtained from one Table
FROM Table A
LEFT JOIN &A.TABLENAME B
ON A.ID = B.ID;
I am not sure how I could do this in SAS. Any help regarding this would be helpful
Thanks in advance.
02-17-2015 03:01 PM
You might need to provide a few more details of what you are trying to accomplish. It almost looks as if you want the use the name of a table that is stored in a data set and then select some data associated with that table.
If that is the case you may be looking for Call Execute in a data step.
02-18-2015 05:11 AM
I do not know what exactly your query needs to be, write your query into a file while reading from the first table and then use %INCLUDE to run the code written to the file. See sample below:
02-18-2015 05:27 AM
There is a couple of functions for this type of thing. call sub() and call execute(). I tend to focus on the second:
call execute('proc sql;
create table WORK.OUTPUT as
from WORK.TABLEA A
left join '||strip(tablename)||' B
on A.ID = B.ID;
What the above does is for every record in tablea, creates a text string which is sent to the compiler. The text in the call execute() procedure can be formed by any normal SAS string processing, in this case I concatenate the tablename from the dataset into the sql clause.
Note I haven't checked the logic in your SQL clause, just copied and pasted.
02-18-2015 06:42 AM
I try to define your problem:
TableX has ID and Tname
TableA, TableB and TableC have ID and some_data
I suggest something like
data want (keep=ID some_data);
TableA (in=a rename=(some_data=some_data_a))
TableB (in=b rename=(some_data=some_data_b))
TableC (in=c rename=(some_data=some_data_c))
when ('TableA') do; if a then some_data = some_data_a; end;
when ('TableB') do; if b then some_data = some_data_b; end;
when ('TableC') do; if c then some_data = some_data_c; end;