猜代码的原意思是:第二个代码想把work.one里面的汇总按照o数据里面出现的rep进行读取。
如果上面的猜测是对的,那么代码的写法是有问题的。
按照程序逻辑我补上了完整的带结果的代码:
data one;
rep='A';cost=1;output;
rep='A';cost=10;output;
rep='B';cost=3;output;
rep='A';cost=5;output;
run;
data o;
rep='B';output;
run;
proc sql;
create table test1 as
select rep, max(cost)
from work.one
group by rep;
quit;
proc sql;
create table test2 as
select o.rep, (select max(cost) from work.one as i where i.rep=o.rep)
from work.one as o
group by rep;
quit;
如果希望按照o里面的rep统计work.one的结果:
proc sql;
create table test3 as
select rep, max(cost)
from work.one
where rep in (select rep from work.o)
group by rep;
quit;