我想知道是否有可能对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;
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢.谢谢!
这样的事可能有用.&&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();
Run Code Online (Sandbox Code Playgroud)