由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - What's the wrong with this SAS code?
相关主题
which route in SAS is faster?[SAS] Efficient way for subsetting data?
a question about SAS codeSAS Code question? How to understand this output?
问个效率问题 SQL vs data step,大数据量昨天考了SAS ADVANCED,不难
SAS菜鸟请教如果使SAS的output的结果放到一个文件内?[合集] 用SAS生成表格,怎么弄比较好?
求教一个简单的data step 牛肉包请教一sas code
SAS help : Proc datasetSAS - please help!
SAS bar chart 求助SAS DATA 求助
新人求问SAS简单问题~~SAS应用问题
相关话题的讨论汇总
话题: conc话题: what话题: sas话题: st1话题: st2
进入Statistics版参与讨论
1 (共1页)
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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 你要是不很明白就先把所有的record先merge到一个table里面,然后用proc means算。
g*******y
发帖数: 380
6
仔细看了一下自己的code,感觉明白你说的意思了。
问题出在avg(a.conc)上面是吗?这个a还是在用原来的数据,而不是根据criteria
match之后剩下的数据,要实现我的想法,这个a要在下面的select里面写一个view让他
们先subset才行。
谢谢。

ave
agai

【在 q**j 的大作中提到】
: 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.

1 (共1页)
进入Statistics版参与讨论
相关主题
SAS应用问题求教一个简单的data step 牛肉包
SAS memory managementSAS help : Proc dataset
SAS format 的问题SAS bar chart 求助
求教proc sql 问题新人求问SAS简单问题~~
which route in SAS is faster?[SAS] Efficient way for subsetting data?
a question about SAS codeSAS Code question? How to understand this output?
问个效率问题 SQL vs data step,大数据量昨天考了SAS ADVANCED,不难
SAS菜鸟请教如果使SAS的output的结果放到一个文件内?[合集] 用SAS生成表格,怎么弄比较好?
相关话题的讨论汇总
话题: conc话题: what话题: sas话题: st1话题: st2