e***7 发帖数: 862 | 1 My data looks like below:
id id_num score
1 1 12
1 2 14
1 3 12
2 1 15
2 2 15
3 1 11
3 2 12
I want to create an indicator say within each id, their score are different
(as long as one is different from another)
So it will look like:
id id_num score ind
1 1 12 1
1 2 14 1
1 3 12 1
2 1 15 0
2 2 15 0
3 1 11 1
3 2 12 1
Sorry cant type Chinese, Any inputs will be appreciated ! | w*******9 发帖数: 1433 | 2 可以先选出符合条件的id, 在left join回去。
proc sql;
create table indicator as
select id, 1 as ind from RawData
group by id
having max(score) = min(score);
quit; | e***7 发帖数: 862 | 3 this works for numerical var (score), if my variable is a char variable, say
A, B, C how can I do it? Thanks!
【在 w*******9 的大作中提到】 : 可以先选出符合条件的id, 在left join回去。 : proc sql; : create table indicator as : select id, 1 as ind from RawData : group by id : having max(score) = min(score); : quit;
| w*******9 发帖数: 1433 | 4 I guess it still works. Letters have magnitudes in SAS.
say
【在 e***7 的大作中提到】 : this works for numerical var (score), if my variable is a char variable, say : A, B, C how can I do it? Thanks!
| e***7 发帖数: 862 | 5 if my var Field is something like ABS, HHJ, just curious how to select out
the flag ones
【在 w*******9 的大作中提到】 : I guess it still works. Letters have magnitudes in SAS. : : say
| w*******9 发帖数: 1433 | 6 It does not matter. You do not need its exact numeric value. If you're
worried about this, you can count the unique number of records within each
id, then flag those having 1 distinct value.
proc sql;
select id, count(distinct(score)) as count from RawData
group by id;
quit;
【在 e***7 的大作中提到】 : if my var Field is something like ABS, HHJ, just curious how to select out : the flag ones
| l****u 发帖数: 529 | 7 proc sql;
create table two as
select *, min(score)^=max(score) as ind1, min(band)^=max(band) as ind2
from yourdata
group by id;
quit; |
|