SAS中文论坛

标题: 求助!编程 [打印本页]

作者: shiyiming    时间: 2007-2-13 02:22
标题: 求助!编程
作业不会做!

Flag: A flag variable which indicates whether a student’s score increased or decreased from the previous year. That is, mark a “zero” for each year a student’s score was lower than the previous year. Conversely, mark a “one” for each year a student’s score was equal or higher than the previous year.  

Q3. Write a SAS macro to create individual student files for each student/year combination.

data:
Student        Year        Score
A        91        400
A        92        398
B        91        455
B        92        432
B        93        444
B        94        446
C        91        412
C        92        423
C        93        411
C        94        415
C        95        413
C        96        418
作者: shiyiming    时间: 2007-2-16 22:33
标题: RE:
[code:2b12e]data b;
set a;
by Student year;
f=(score-lag(score))>=0;
if first.Student then f=.;
run;[/code:2b12e]
作者: shiyiming    时间: 2007-2-17 10:05
标题: 还可以更短
[code:9f0ca]data b;
  set a;
  by Student year;
  f=(score>lag(score))*(not first.student);
run;[/code:9f0ca]
作者: shiyiming    时间: 2007-2-21 22:55
标题: RE:
ahuige, nice code.  But it is more meaningful if the Flag is treated as a missing value for First.student.  don't you think so?




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2