Note that PROC SQL is NOT the right tool for generating the mean of multiple variables. Use PROC MEANS (aka PROC SUMMARY).
But to fix your current code you need to do two things.
1) Figure out what SQL code you need to generate.
2) Change your macro variable to contain that code.
data new ;
set sashelp.class;
if name = 'Alfred' then name = 'Alice';
if name = 'Janet' then name = 'Judy';
if name = 'Robert' then name = 'Ronald';
run;
proc contents noprint data=new(keep=height weight) out=names(keep=name);
run;
proc sql noprint;
select catx(' ','mean(',Name,') as',cats('m_',name))
into :sql_code separated by ','
from names
;
%put &=sql_code ;
create table new_1 as
select Name, &sql_code
from new
group by name
;
quit;
... View more