SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1243|回复: 3
打印 上一主题 下一主题

求助!编程

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2007-2-13 02:22:36 | 只看该作者

求助!编程

作业不会做!

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
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2007-2-16 22:33:06 | 只看该作者

RE:

[code:2b12e]data b;
set a;
by Student year;
f=(score-lag(score))>=0;
if first.Student then f=.;
run;[/code:2b12e]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2007-2-17 10:05:50 | 只看该作者

还可以更短

[code:9f0ca]data b;
  set a;
  by Student year;
  f=(score>lag(score))*(not first.student);
run;[/code:9f0ca]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2007-2-21 22:55:47 | 只看该作者

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?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-6-12 19:13 , Processed in 0.068112 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表