02-21-2014 01:28 PM
Hello all, I have another (maybe simple) question. I have the following macro
%macro mytest(dataset, dataset1, myfldget, myfldon);
create table &dataset as select a.*, b.&myfldget from &dataset a left join &dataset1 b on a.&myfldon = b.&myfldon;
%mytest(myfinal, myfinal, age, date);
I was wondering is there a way I can pass a set of columns to myfldget like age, sales, etc rather than calling this macro again substituing age with sales? THanks very much for your help
02-21-2014 03:37 PM
Try using this
%let a= %str(a.ages,a.sales);
so &a = a.ages, a.sales
You can write all the required fields in a single variable and pass it to the macro.
Hope this helps !
02-21-2014 07:23 PM
I recommend using normal SAS space delimited variable lists when passing them into macros.
So to do what you want you could use this simple macro:
merge &in1(in=in1) &in2(keep &keys &vars);
Then the call to add both AGE and SEX would be:
Now if you really want to use SQL, don't force the users to type commas and then have to add macro quoting to prevent the commas from confusing the macro call. Just convert the spaces to commas inside the macro.
%local varlist join i ;
%let varlist=b.%sysfunc(tranwrd(&varlist,%str( ),%str(, b.)));
%do i=1 %to %sysfunc(countw(&keys));
%if &i > 1 %then %let join=&join and ;
%let join=&join a.%scan(&keys,&i)=b.%scan(&keys,&i) ;
proc sql noprint ;
create table &out as
from &in1 a left join &in2 b