楼主: windvally
1636 5

如何统计并列出累计成绩? [推广有奖]

  • 0关注
  • 0粉丝

高中生

0%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
95 点
帖子
18
精华
0
在线时间
18 小时
注册时间
2014-4-21
最后登录
2014-4-29

楼主
windvally 发表于 2014-4-29 08:06:11 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
首先这个是我的Code:
data base;
    infile  'C:\Users\mayan\Documents\Statistics 224\Final_Data\*.txt' delimiter='@';
    input stud $ semester $ course $ score  GPA $;
    Abb_Course = substr(course,1,4);
    School_Year= substr(semester,2,2);
    run;
    data base;
    set base;
    if substr(GPA,1,1)='A' then new_GPA=4;
    else if substr(GPA,1,2)='A+' then new_GPA=4.33;
    else if substr(GPA,1,2)='A-' then new_GPA=3.66;
    else if substr(GPA,1,2)='B+' then new_GPA=3.33;
    else if substr(GPA,1,2)='B' then new_GPA=3;
    else if substr(GPA,1,2)='B-' then new_GPA=2.66;
    else if substr(GPA,1,2)='C+' then new_GPA=2.33;
    else if substr(GPA,1,2)='C' then new_GPA=2;
    else if substr(GPA,1,2)='C-' then new_GPA=1.66;
    else if substr(GPA,1,2)='D+' then new_GPA=1.33;
    else if substr(GPA,1,2)='D' then new_GPA=1;
    else if substr(GPA,1,2)='D-' then new_GPA=0.66;
    else if substr(GPA,1,2)='E' then new_GPA=0;
    else new_GPA=.;
    run;
    data base;
    set base;
    if substr(semester,1,1)='1' then Semester_Season='Fall';
    else if substr(semester,1,1)='2' then Semester_Season='Spr';
    else if substr(semester,1,1)='3' then Semester_Season='Sum';
    else if substr(semester,1,1)='5' then Semester_Season='Win';
    else Semester_Season=.;
    run;
    data base;
    set base;
    if substr(semester,1,1)='1' then Semester_Order='1';
    else if substr(semester,1,1)='2' then Semester_Order='3';
    else if substr(semester,1,1)='3' then Semester_Order='4';
    else if substr(semester,1,1)='5' then Semester_Order='2';
    else Semester_Order=.;
    run;
    proc sort data=base;
    by stud School_Year Semester_Order;
    run;
    proc sql;
        create table base1
        as select stud,School_Year,Semester_Season,mean(new_GPA) as mean_GPA,
        sum(score) as sum_score,
        count(*) as num_course from base
        group by stud,semester,School_Year,Semester_Season;
    quit;
    proc print data=base1;
    run;

最后打出来的表如下:
结果表
如何才能在每行的最后加上一个Cumulative GPA (学期累计成绩),如图第一个就是那个学期成绩,第二个就是两个学期的平均成绩[(3.47571+3.33167)/2],第三个就是3个学期的平均成绩。而且一定要按学生(学生号是第一列)区分。

我大概猜到是不是应该用一个loop?但是不知道怎么下手,请高手帮忙 ORZ

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:cumulative Statistics documents delimiter statistic 如何 统计

沙发
frankzhao0829 发表于 2014-4-29 08:30:13
可以用如下code 计算cumulative GPA:
data base1 (drop= count GPA);
set base1;by stud;
retain count GPA;
if first.stud then do;
count=0;
GPA=0; end;
count+1; GPA+mean_GPA;
Cumulative_GPA=GPA/count;
run;




藤椅
windvally 发表于 2014-4-29 08:44:43
插入上面的那个code后第一个学生没有问题,但是到了下一个学生后,累计成绩没有清零,如图:
问题

板凳
frankzhao0829 发表于 2014-4-29 08:45:46
windvally 发表于 2014-4-29 08:44
插入上面的那个code后第一个学生没有问题,但是到了下一个学生后,累计成绩没有清零,如图:
刚才我忘加by stud;语句了,你加上by 语句再试试

报纸
windvally 发表于 2014-4-29 08:50:25
啊,成功了,非常感谢!

地板
苹果叶 在职认证  发表于 2014-5-2 00:05:29
  1.     if substr(GPA,1,1)='A' then new_GPA=4;
  2.     else if substr(GPA,1,2)='A+' then new_GPA=4.33;
  3.     else if substr(GPA,1,2)='A-' then new_GPA=3.66;
  4.     else if substr(GPA,1,2)='B+' then new_GPA=3.33;
  5.     else if substr(GPA,1,2)='B' then new_GPA=3;
  6.     else if substr(GPA,1,2)='B-' then new_GPA=2.66;
  7.     else if substr(GPA,1,2)='C+' then new_GPA=2.33;
  8.     else if substr(GPA,1,2)='C' then new_GPA=2;
  9.     else if substr(GPA,1,2)='C-' then new_GPA=1.66;
  10.     else if substr(GPA,1,2)='D+' then new_GPA=1.33;
  11.     else if substr(GPA,1,2)='D' then new_GPA=1;
  12.     else if substr(GPA,1,2)='D-' then new_GPA=0.66;
  13.     else if substr(GPA,1,2)='E' then new_GPA=0;
  14.     else new_GPA=.;
复制代码


这段code 是否有问题呢? 比如 GPA = ‘A+’ 时,满足了 if substr(GPA,1,1)='A' then new_GPA=4; 下面的 else if 就不执行了。现在跑出来结果应该是 A ,A+, A- 的 GPA 都等于 4 ?下面的 B C D 也有问题(假如所有数据都如code 一样标准,BCD是没错的,因为substr(GPA,1,2)  里面的 2 很关键      )。个人感觉逻辑不够严谨。

如有错误,还请指出,还望不要见怪

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-17 13:00