I'm not sure that's it.. I'm still getting the same error:
%macro Test(variables) ;
%let varlist=%sysfunc(tranwrd(%sysfunc(compbl(&variables)),%str( ),%str(,)));
PROC SQL ;
Create table Table3 as Select
T1.*,
T2.temp
FROM Table1 as T1
LEFT JOIN Table2 as T2
%let prefix=ON ;
%do i=1 %to %sysfunc(count(&varlist));
&prefix T1.%scan(&varlist,&i) = T2.%scan(&varlist,&i)
%let prefix=AND ;
%end ;
Order by &varlist
; quit ;
%mend ;
%test(var1 var2) ;
You have changed the value of VARLIST to be the version with comma. So you need to protect the commas from being read by the %SCAN() function. You could add quoting.
%let x=a,b ;
%put %scan(%superq(x),1);
Or you could just use two different macro variables for the list with and without commas.
%local varlistc ;
%let varlistc=%sysfunc(tranwrd(%sysfunc(compbl(&variables)),%str( ),%str(,)));
Thank you very much Tom, i've gotten the code to work.
For your example application SQL is probably not the preferred solution. Use PROC SUMMARY.
%macro sum(classvars,sumvars,in,out);
proc summary nway data=&in ;
class &classvars;
var &sumvars ;
output out=&out sum= ;
run;
%mend sum;
%sum(classvars=sex age,sumvars=height weight,in=sashelp.class,out=sum1);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.