SAS Proc表示将平均值存储为变量

时间:2013-12-05 13:31:47

标签: sas

我需要找到两个平均值的比率,我发现使用proc方法。

proc means data=a;
class X Y;
var x1 x2;
run;

然后我得到X和Y这两个类别中变量x1和x2的输出平均值,但对于我感兴趣的每个类别它都是x1 / x2,而手工完成并不是真正的解决方案。

我不是专业的程序员,所以我希望有一段我能理解和使用的简单代码。

2 个答案:

答案 0 :(得分:1)

您需要预先计算x1 / x2或后计算x1 / x2(取决于您是否需要mean(x1/x2)mean(x1)/mean(x2),其中x1和x2的不同答案具有不同的响应数量。)< / p>

所以(...意味着填写你已经拥有的东西)

data premean;
set have;
x1x2 = x1/x2;
run;

proc means ... ;
class ... ;
var x1x2;
run;

proc means ...;
class ... ;
var x1 x2;
output out=postmeans mean=;
run;

data want;
set postmeans;
x1x2=x1/x2;
run;

答案 1 :(得分:0)

proc sql noprint;

    create table xy_ratio as /* New table name*/
    select distinct X, Y, avg(x1)/avg(x2) as x1_x2_ratio /* selects distinct rows containing variables listed here. (Must include group by variables) mean of x1 / mean of x2 to form ratio*/
    from a /*source dataset*/
    group by X, Y /*Similar to class statement, will provide an average for each distinct combination of X and Y that appear in the dataset*/
    ;
quit;