g*******y 发帖数: 380 | 1 proc sql;
create table test as
select a.homolog, a.weather, avg (a.conc) as conc_st1, avg(b.conc) as
conc_st2
from st1 as a,
(select * from st2
where conc ne 0 )as b
where a.homolog=b.homolog and a.weather=b.weather and a.cas=b.cas
group by a.homolog, a.weather;
quit;
The idea is get the average conc value by weather and homolog based on the
observations which has common homolog, weather, cas# in both datasets.
However, it doesn't give me the correct averaged |
q**j 发帖数: 10612 | 2 nothing surprising. they should not be the same. first group then taking ave
rage is not the same as taking subgroup average, group and then average agai
n.
【在 g*******y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : proc sql; : create table test as : select a.homolog, a.weather, avg (a.conc) as conc_st1, avg(b.conc) as : conc_st2 : from st1 as a, : (select * from st2 : where conc ne 0 )as b : where a.homolog=b.homolog and a.weather=b.weather and a.cas=b.cas : group by a.homolog, a.weather; : quit;
|
g*******y 发帖数: 380 | 3 能解释的详细点吗?
看的有点头晕,哪个是在先集合求平均,哪个是sub平均再平均?
为什么会造成这样的区别?
怎样修改以上的code才能实现所想要得到的平均?
ave
agai
【在 q**j 的大作中提到】![](/moin_static193/solenoid/img/up.png) : nothing surprising. they should not be the same. first group then taking ave : rage is not the same as taking subgroup average, group and then average agai : n.
|
q**j 发帖数: 10612 | 4 你要是不很明白就先把所有的record先merge到一个table里面,然后用proc means算。 |
g*******y 发帖数: 380 | 5 可能我说的不明白,在第二段里我提到了,我分别用了几个不同的proc sql,先用proc
sql把两个dataset里拥有共同category(same homologue,same weather, same cas
#),然后用这个list分别subset两个数据,再在每个数据里求same homologue,same
weather的平均,这样的结果是我所想要得到的。
但是用我原贴里的code就达不到这样的目的,我不明白问题出在了哪里?
【在 q**j 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 你要是不很明白就先把所有的record先merge到一个table里面,然后用proc means算。
|
g*******y 发帖数: 380 | 6 仔细看了一下自己的code,感觉明白你说的意思了。
问题出在avg(a.conc)上面是吗?这个a还是在用原来的数据,而不是根据criteria
match之后剩下的数据,要实现我的想法,这个a要在下面的select里面写一个view让他
们先subset才行。
谢谢。
ave
agai
【在 q**j 的大作中提到】![](/moin_static193/solenoid/img/up.png) : nothing surprising. they should not be the same. first group then taking ave : rage is not the same as taking subgroup average, group and then average agai : n.
|