由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - sas programming question
相关主题
PROC SQL join data helpsas问题
请教一sas programmm请教如何用SAS计算多个变量的missing value?
help for a sas question请教flag问题
[提问]怎样sort这个dataset?question about using sas macro variable and do loop
sas adv 63题 52如何比较两个proc contents的结果?
SAS problem ask for help!求教proc sql 问题
Please help with a SAS macroone quick question about concatenating data in SAS
sas 题目问问问个proc merge问题。
相关话题的讨论汇总
话题: score话题: name话题: missing话题: set话题: score2
进入Statistics版参与讨论
1 (共1页)
J*y
发帖数: 271
1
I have a dataset looks as the following:
Name Score
A 766
A 9
A 93
A 869
A 143
B 8
B 119
B 362
B 6
B 95
C 524
C 99
C 123
C 176
C 210
...
I need to do the following:
1. if the score value less than 10, set the score to missing
2. if there is only one score less than 10 for each name group, then set the
second minimum score to missing. (that's where I am stuck. )
for example, the above table:
for Name A, 9 and 93 should set to missing;
for Name B, 8 and 6 should set to missing ...
BTW, the number of each name is always 5.
s*********e
发帖数: 1051
2
这行吗?
data one;
input Name $ Score;
if score < 10 then score = .;
datalines;
A 766
A 9
A 93
A 869
A 143
B 8
B 119
B 362
B 6
B 95
C 524
C 99
C 123
C 176
C 210
;
run;
proc sort data = one;
by name score;
run;
data two;
set one;
by name score;
if first.name then n = 1; else n + 1;
if n = 2 and lag(score) = . then score = .;
run;
proc print data = _last_; run;
m***c
发帖数: 118
3
proc sql;
create table final(drop=n score2) as
select *,ifn(n=1and score2=min(score2),.,score2) as score3
from (select *,ifn(score<10,.,score) as score2,sum(score<10) as n from
one group by name)
group by name
order by name;
quit;
J*y
发帖数: 271
4
Thank you!
I changed missing value to 999999, then sort and get the first, and then
reset to missing. Obviously yours are better than mine by using lag
function.

【在 s*********e 的大作中提到】
: 这行吗?
: data one;
: input Name $ Score;
: if score < 10 then score = .;
: datalines;
: A 766
: A 9
: A 93
: A 869
: A 143

J*y
发帖数: 271
5
It works. Thanks.

【在 m***c 的大作中提到】
: proc sql;
: create table final(drop=n score2) as
: select *,ifn(n=1and score2=min(score2),.,score2) as score3
: from (select *,ifn(score<10,.,score) as score2,sum(score<10) as n from
: one group by name)
: group by name
: order by name;
: quit;

1 (共1页)
进入Statistics版参与讨论
相关主题
问个proc merge问题。sas adv 63题 52
help with SAS sqlSAS problem ask for help!
a sas merge questionPlease help with a SAS macro
求一段SAS codesas 题目问问
PROC SQL join data helpsas问题
请教一sas programmm请教如何用SAS计算多个变量的missing value?
help for a sas question请教flag问题
[提问]怎样sort这个dataset?question about using sas macro variable and do loop
相关话题的讨论汇总
话题: score话题: name话题: missing话题: set话题: score2