由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - sas 题目问问
相关主题
sas programming question[提问]怎样sort这个dataset?
SAS question%do questions
a sas merge question请教一下SAS编程的一个问题
求一段SAS code遇到个SAS 问题,求教
PROC SQL join data helpsas adv 63题 52
请教sas code问题SAS problem ask for help!
请教一sas programmmquestion about SAS BASE 123 No.64?
help for a sas questionhelp on a sas question
相关话题的讨论汇总
话题: score话题: studentid话题: flag话题: student
进入Statistics版参与讨论
1 (共1页)
n*****5
发帖数: 61
1
Consider the following dataset:
data StudentScore;
length studentID $ 1. year 3. score 3.;
input studentID year score;
datalines;
A 91 400
A 92 398
A 92 399
B 91 430
B 92 432
B 93 444
B 94 446
C 91 455
C 92 423
C 93 411
C 94 415
C 95 427
C 95 418
run;
Q1. Create a variable called “Flag” which indicates whether a student’s
score increased or decreased from the previous record in the data. Mark a “
0” for records where the student’s score was lower than the previous
record. Conversely, mark a “1” for records where a student’s score was
equal or higher than the previous record. Mark a “0” for the first record
of each student.
Q2. Write code to create a SAS dataset named “StudentScoreNew” that
contains each student’s most recent score. If there are multiple scores for
the most recent year, then pick the highest one for that year.
a****y
发帖数: 1719
2
我也是刚学sas 试着写了一个,不知道对不对,你可以参考一下
data studentscore;
set studentscore;
by studentid;
retain temp flag;
if first.studentid then do;
temp=score;
flag=0;
end;
if temp < score then do;
flag=1;
temp=score;
end;
if temp > score then do;
flag=0;
temp=score;
end;
run;
s****u
发帖数: 1200
3
好像不是和第一个比,而是和上一个比。用lag 省事

★ 发自iPhone App: ChineseWeb 7.8

【在 a****y 的大作中提到】
: 我也是刚学sas 试着写了一个,不知道对不对,你可以参考一下
: data studentscore;
: set studentscore;
: by studentid;
: retain temp flag;
: if first.studentid then do;
: temp=score;
: flag=0;
: end;
: if temp < score then do;

c*****i
发帖数: 1392
4
Q1:
data flag(drop=prevID prevscore);
set StudentScore;
if _n_=1 then flag=0;
else do;
set StudentScore(drop=year rename=(studentID=prevID score=prevscore));
if studentID ^= prevID then flag=0;
else if score else flag=1;
end;
run;
Q2:
proc sort data=StudentScore;
by studentID year score;
run;
data StudentScoreNew;
set StudentScore;
by studentID year score;
if last.studentID;
run;
1 (共1页)
进入Statistics版参与讨论
相关主题
help on a sas questionPROC SQL join data help
question about using sas macro variable and do loop请教sas code问题
Please help with a SAS macro请教一sas programmm
Another SAS questionhelp for a sas question
sas programming question[提问]怎样sort这个dataset?
SAS question%do questions
a sas merge question请教一下SAS编程的一个问题
求一段SAS code遇到个SAS 问题,求教
相关话题的讨论汇总
话题: score话题: studentid话题: flag话题: student