楼主: yellowriver
1976 2

[原创博文] SAS新手竭诚求教代码编写(1) [推广有奖]

  • 0关注
  • 4粉丝

VIP

已卖:5081份资源

博士生

38%

还不是VIP/贵宾

-

威望
0
论坛币
10034 个
通用积分
22.8832
学术水平
21 点
热心指数
26 点
信用等级
19 点
经验
3133 点
帖子
164
精华
0
在线时间
170 小时
注册时间
2007-11-4
最后登录
2019-5-18

楼主
yellowriver 发表于 2010-11-2 14:23:07 |AI写论文
50论坛币
昨天已经发过一个100论坛币悬赏贴,一位热心网友已经给我详细解答了那个macro代码的各个部分,我把他的答案设为最佳答案,也让大家参考学习一下。我还有几个问题求教各位。这是一个我组上在做的research,按照老板的要求和teammate的讨论,我需要往以下几个方向编代码,SAS新手在此再发两个悬赏帖竭诚向大家求教了。

Sample Data: StudentScore
  

StudentID

  
  

Year

  
  

Score

  
  

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

  

Q1. Create a variable called “inorde” which indicates whethera student’s score increased or decreased from the previous record in the data. Marka “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 higherthan the previous record. Mark a “0” for the first record of each student.

Q2. Write code to create a SAS dataset named“StudentScore2” by picking each student’s most recent score. If there aremultiple scores for the most recent year, then pick the highest one for thatyear.

Q3. Tag on the following variables to “StudentScore2” fromthe above question.

1.
HighScore: the highest score of each student. (Use“StudentScore” as the input)
2.
AvgScore: Average score for each student. (Use“StudentScore” as the input)
关键词:Increased following Variables Students previous research

本帖被以下文库推荐

沙发
soporaeternus 发表于 2010-11-2 14:23:08
  1. /*INPUT*/
  2. data StudentScore;
  3.         input StudentID $ Year Score;
  4.         datalines;
  5.         A 91 400
  6.         A 92 398
  7.         A 92 399
  8.         B 91 430
  9.         B 92 432
  10.         B 93 444
  11.         B 94 446
  12.         C 91 455
  13.         C 92 423
  14.         C 93 411
  15.         C 94 415
  16.         C 95 427
  17.         C 95 418
  18.         ;
  19. run;

  20. /*Q1*/
  21. data StudentScore;
  22.         set StudentScore;
  23.         by StudentID;
  24.         retain Score_lag;
  25.         if Score>=Score_lag then inorde='1';
  26.         else inorde='0';
  27.         if first.StudentID then  inorde='0';
  28.         Score_lag=Score;
  29.         drop Score_lag;
  30. run;

  31. /*Q2*/
  32. proc sort data=StudentScore out=StudentScore2;
  33.         by StudentID descending year descending Score;
  34. run;quit;

  35. data StudentScore2;
  36.         set StudentScore2;
  37.         by StudentID descending year descending Score;
  38.         if first.StudentID;
  39.         keep StudentID Score;
  40. run;

  41. /*Q3*/
  42. proc sql;
  43.         create table StudentScore2 as
  44.                 select
  45.                         a.*
  46.                         ,max(b.score) as HighScore
  47.                         ,avg(b.score) as AvgScore
  48.                 from StudentScore2 a
  49.                 inner join StudentScore b
  50.                 on a.StudentID=b.StudentID
  51.                 group by
  52.                         a.StudentId
  53.                         ,a.Score
  54.         ;               
  55. quit;
复制代码
已有 3 人评分学术水平 热心指数 信用等级 收起 理由
hopewell + 1 + 1 + 1 我很赞同
pobel + 1 + 1 + 1 我很赞同
peijiamei + 2 好的意见建议

总评分: 学术水平 + 2  热心指数 + 4  信用等级 + 2   查看全部评分

Let them be hard, but never unjust

藤椅
chouxiangdaishu 发表于 2010-11-3 09:56:03
yellowriver  发表于 2010-11-2 14:23

soporaeternus 发表于 2010-11-2 14:23

终于知道了,什么是秒杀。。。

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 03:39