0

I am trying to join over 15 tables and I wrote a macro which has two do loops and the program I wrote is this way.

%macro joinnow (year, Tno); 
%do year=1991 %to 2012; 
%do Tno=2 % to 23; 
Full join A_&year T&Tno ON T1.ID=T&Tno.ID
%End;
%End;
%mend;

Now I run the program

Proc sql; 
create table NEW_tab as 
    Select T1.*, T2.reg_1991,-----,T23.reg_2012
    from  A_1990 T1
    %joinnow; 
; 
Quit; 

I get an error saying

ERROR: Column reg_2002 could not be found in the table/view identified with     the correlation name T13.

where as the reg_2002 is present in T13

Can you see where the error is?

user3658367
  • 641
  • 1
  • 14
  • 30
  • I would trust the error message and check your source data again. Try removing the macro language and just join T1 and T13 to see if you get the same error. – Quentin Jun 15 '15 at 10:51
  • @Quentien When I remove the macro language and write all the statements it works. But as you know I want to shorten the program so I am trying to write this macro. – user3658367 Jun 15 '15 at 10:58
  • @Quentin hey, I solved it., I just took away the first do loop and put a eval instead.! – user3658367 Jun 15 '15 at 12:55
  • Glad you got it. You should post the answer. Looks like you wanted to generate 22 full join clauses. But with nested do loops as they are, you would generate 22•22 clauses. Probably not what you intended. – Quentin Jun 15 '15 at 14:53
  • @Quentin Yes I will post the answer here., `code` %macro joinnow (year, Tno); `code` %do Tno=2 % to 23; `code` %let year=%eval(1990+&tno); `code` Full join A_&year T&Tno ON T1.ID=T&Tno.ID `code` %End; 'code' %mend; – user3658367 Jun 15 '15 at 15:17

0 Answers0