data t1;
input id;
cards;
1
2
3
4
5
;
run;
data t2;
input id;
cards;
5
6
7
8
;
run;
%macro left(left,right ,var);
proc sql;
select *
from &left as a
left join &right as b
on a.&var=b.&var;
quit;
%mend;
%left(t1,t2,id);
Here I am trying to join table with macro application
how to define joins for
left join
right join
full join
inner join
need help me
above code is correct
Why do you want to do this? The SAS macro language is for generating code. Why not just write the joins with no macro?
And if this is for practice, why do you want the answer rather than trying yourself?
@BrahmanandaRao wrote:
Here I am trying to join table with macro application
how to define joins for
left join
right join
full join
inner join
need help me
above code is correct
Is the question that you want the code to do something other than a left join?
You can simply add another argument into the macro definition that will specify the type of join.
data t1;
input id;
cards;
1
2
3
4
5
;
run;
data t2;
input id;
cards;
5
6
7
8
;
run;
%macro abc(left,right ,var,j_type);
proc sql;
select *
from &left as a
&j_type &right as b
on a.&var=b.&var;
quit;
%mend;
%abc(t1,t2,id,right_join);
Your macro, when all the macro variables resolve, must produce working valid legal SAS code — and it does not produce working valid legal SAS code. That's what the log is showing you. A very trivial change fixes this.
If it's still not obvious, then you need to go back to the first step in macro writing, which is to produce code that works (in this case for your right join) without macros and without macro variables. Once you have this working, you should be able to turn it into a macro that works. If you can't produce working SAS code without macros and without macro variables, then it will never work when you add macros and add macro variables.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.