【问题标题】:Making an (iterative?) Do loop in SAS在 SAS 中进行(迭代?)循环
【发布时间】:2016-03-10 02:52:09
【问题描述】:

我知道这很简单,但我似乎无法弄清楚。

我有一个包含 50 名学生的数据集,其中一列称为测试分数,其中包含每个学生的测试分数。我需要通过并找到所有学生之间的差异 - 所以学生 1 分数 - 学生 2 分数,学生 2 分数 - 学生 3 分数......到 50 然后学生 2 分数 - 学生 3 分数,......学生2分数-学生50分数。

我基本上需要得到一个测试分数差异矩阵。

我必须使用一个数组 - 所以它会像 数据: 学生成绩 亚历杭德罗 91 阿特金辛 87 比尔72 管家 94 科尔曼 91

data array;
set testscores;
array score(50) Score1-Score 50; ?I dont think this is correct
do i=1 to 50;
difference= score(i) -score(i+1)?? I really have no idea everything I try isn't working 
end;
run;

我需要得到一个让每个学生的分数都不同的东西

【问题讨论】:

  • 代码取决于你的数据结构。您需要显示示例数据。这听起来也像一个距离矩阵,所以 proc 距离可能是最简单的方法。
  • 我同意 Reeza 的观点,添加一些示例数据将大大提高您获得帮助的机会。

标签: arrays sas do-loops


【解决方案1】:

第一个数据步骤根据 50 名学生的均匀分布生成介于 1 (a) 和 100 (b) 之间的随机分数。

然后 proc distance 计算每个学生与所有其他学生的分数之间的差异。为此,“Student”应该是一个字符变量。

data scores;
    a = 1;
    b = 100;
    do Student_temp = 1 to 50;
        Student = compress(put(student_temp, 8.));
        u = ranuni(12345);
        Score = floor(a + (b-a)*u);
        output;
    end;
    drop Student_temp a b u;
run;

proc distance data=scores out=Diff method=Euclid;
    var interval(score);
    id Student;
run;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2020-10-21
    • 2019-11-28
    • 2010-09-11
    相关资源
    最近更新 更多