p**********r 发帖数: 10 | 1 I have the following dataset data1:
var num1 num2 count
a 1 11 2
a 1 11 2
b 2 21 1
c 3 45 3
c 3 45 3
c 3 45 3
count实际上就是# of ob in group(var num1 num2)
我的问题时,我想要挑出count最大的那个组,记录下num1,num2,然后用这两个 |
g*******y 发帖数: 380 | 2 说实在的,不懂你在说什么?
第一,你所指的保留值是什么?是指你在data1里提取的count的值为最大的组里对应的
num1,num2吗?
第二,不懂你为什么要想那么多复杂的方法?因为从你的sample来看,你的每个组只是根
据count的值来进行重复,count是多少,每个组重复的观察值就是几个.你如果只是想要
count最大组里的num1,num2来剔取data2里的观察值的话.我觉得最简单的方法:
proc sort data=data1; by descending count;
用最大count组里的值,比如x,y来剔除你不要的观察值.
data temp; set data2; if num1=x and num2=y;
如果这个不是你想要的,那么也许我没有看懂你的问题. |
p**********r 发帖数: 10 | 3 多谢啊,可能使我表述得太差了,但需要的就是这个结果。
我也想过用这个方法,但是这中间有一个手动纪录num1 num2的过程,如果对1000+不同
的样本做会很麻烦,而且实际上我需要比较的值除了num1 num2之外还有num3 num4。。。
不知有没有什么办法? |
g*******y 发帖数: 380 | 4 I still don't understand why do you care the number of observations?
What you need is just the observation which has the maximum count,right? If
you really don't like type the value of each variable, try to get it by
subset data or using proc means, then you can use proc sql to join dataset
by using:
"where a.num1=b.num1 and a.num2=b.num2 and..." |
p**********r 发帖数: 10 | 5 u r right. i know the question is quite preliminary.
but how shall i right the proc sql code in this case pls?
i have never used proc sql before...sorry that im not from stat background.
thanks so much! |
w***y 发帖数: 114 | 6 I donot understand what you mean?
if you only want the max count in data a that means final data a only have
one obs? or you want var as group
proc sql;
create data derived_a as
select var, num1, num2, max(count) as count
from a
group by var /*if you donot want it, just delete it*/
order by var
;
quit;
then you can combine two dataset together
proc sql;
create table a_b as
select b.*, a.count
from b as b, derived_a as a
where b.num1=a.num1 and b.num2=a.num2
;
quit;
Good luck |
g*******y 发帖数: 380 | 7 Then trying this:
proc sql;
create table new as
select a.*
from data2 as a
right join (select distinct num1, num2
from (select * , max(count) as max_count
from data1
having count=calculated max_count)) as b
on a.num1=b.num1 and a.num2=b.num2
;
quit; |
g*******y 发帖数: 380 | 8 That's what I'm confused too.
"挑出count最大的那个组".
Suppose he/she really want each group with the observation has maximum count
number? However, for each group, the observations are repeated by "count"
times. What does maximum count mean? In this case, each group only has one "
count" number.
Coding in SAS doesn't require statistics background. If lz really interested
in proc sql, he should be able to figure about by searching examples online
. The problem is what he want to do?
【在 w***y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : I donot understand what you mean? : if you only want the max count in data a that means final data a only have : one obs? or you want var as group : proc sql; : create data derived_a as : select var, num1, num2, max(count) as count : from a : group by var /*if you donot want it, just delete it*/ : order by var : ;
|
p**********r 发帖数: 10 | 9 Thank you guys.
guess i made the question silly to you.
i generate "count" to find the group that has the most obs.
i dont have problem finding the values of num1 and num2 i need.
the problem is that i do not want to manually write down the values and
search for obs with those values in another dataset because i need to repeat
this procedure a few hundred of times.
proc sql is really powerful but im still learning to use it.
thank you again! |
g*******y 发帖数: 380 | 10 The question is not silly though, you just need make it clear. For instance,
by using following format:
Question,
Desired results with good example.
It looks like a simple task for your sample data, but you are trying to do
it hundreds of times? and doing hundreds times for what? why?
Anyway, Good luck!
repeat
【在 p**********r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Thank you guys. : guess i made the question silly to you. : i generate "count" to find the group that has the most obs. : i dont have problem finding the values of num1 and num2 i need. : the problem is that i do not want to manually write down the values and : search for obs with those values in another dataset because i need to repeat : this procedure a few hundred of times. : proc sql is really powerful but im still learning to use it. : thank you again!
|
p**********r 发帖数: 10 | 11 its a finance project. think about gathering quote update for the most
traded options. so the first step is to identify the most traded options for
each stock in the sample. there can be a few hundred. then i need to match
underlying asset, expiration, strike of the options in the quote file to
find quote update.
cheers, |