2011-09-29 83 views
2

我想知道是否可以對SAS中的數據集中的所有變量執行ttest(proc ttest)。可能通過循環數據?SAS中的變量執行測試

這是我目前有,但它無法正常運行:

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; 

任何幫助深表感謝。謝謝!

回答

6

這樣的事情可能會奏效。在循環中調用&&name&i.將引用每個變量名稱。您可能需要在proc測試中進行一些調整,因爲我不熟悉該功能。

/* -- 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(); 
+1

夢幻般的答案 - 我一直在尋找這一切。值得超過三個upvotes。 –