【问题标题】:performing tests over variables in SAS在 SAS 中对变量执行测试
【发布时间】:2011-09-29 00:23:13
【问题描述】:

我想知道是否可以对 SAS 数据集中的所有变量执行 ttest (proc ttest)。可能通过循环数据?

这是我目前拥有的,但运行不正确:

data test;
set work.wisc;
array Avar(30) V1-V30;
do variable = 1 to 30;
    proc ttest data = work.wisc;
    class Diagnosis;
    var Avar(variable);
    end;
run;

非常感谢任何帮助。谢谢!

【问题讨论】:

    标签: sas


    【解决方案1】:

    这样的事情可能会奏效。在循环中调用&&name&i. 将引用每个变量名。您可能需要在 proc ttest 中进行一些调整,因为我不熟悉该功能。

    /* -- Get the names of the variables --*/
    proc contents data = work.wisc out = names noprint;  run;
    
    /*--- Make macro vars needed ---*/
    proc sql noprint;
     select
       count(distinct name) into :name_count from names;
     select
       distinct name into :name1 - :name9999 from names;
    quit;
    
    /*--- Strip spaces from name_count ---*/
    %let name_count = &name_count.;
    
    %put There are &name_count. variables in the data set;
    
    /*--- Run the test for all variables ---*/
    %macro testAll();
    %do i = 1 %to &name_count.;
       proc ttest data = work.wisc;
           class Diagnosis;
           var Avar(&&name&i.);
       run;
    %end;
    %mend;
    %testAll();
    

    【讨论】:

    • 很棒的答案 - 我一直在寻找这个。值得超过三张赞成票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 2016-08-11
    • 2021-04-12
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多