BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DangIT
Fluorite | Level 6

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) ;

Tom
Super User Tom
Super User

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(,)));

DangIT
Fluorite | Level 6

Thank you very much Tom, i've gotten the code to work.

Tom
Super User Tom
Super User

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);

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 18 replies
  • 5851 views
  • 7 likes
  • 5 in conversation