|
LZ 想 用sas sql;
data aaa;
ID = _N_;
input a b c d e f g h;
cards;
1 2 3 4 5 6 7 8
;
proc sql;
create table bbb(drop=id) as
select a.*, (a.a + b.e) as sum_ae, b.*
from aaa (drop=e--h) as a, aaa(drop=a--d) as b
where a.id=b.id;
quit;
或者
data ccc;
input a b c d e f g h;
cards;
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
;
proc sql noprint;
select name into: a_e separated by ', '
from dictionary.columns
where libname='WORK' and memname='CCC' and varnum in (1 2 3 4);
select name into: e_h separated by ', '
from dictionary.columns
where libname='WORK' and memname='CCC' and varnum in (5 6 7 8);
quit;
proc sql;
select &a_e, sum(d) as sum_d, &e_h
from ccc;
quit;
或者用 SQL 和 data step
proc sql noprint;
select name into: a__e separated by ' '
from dictionary.columns
where libname='WORK' and memname='CCC' and varnum in (1 2 3 4);
select name into: e__h separated by ' '
from dictionary.columns
where libname='WORK' and memname='CCC' and varnum in (5 6 7 8);
quit;
data ddd;
retain &a__e sum_de &e__h;
set ccc;
sum_de = d+e;
run;
|