Date: Mon, 30 Mar 2009 16:50:31 -0500
Reply-To: Mary <mlhoward@avalon.net>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mary <mlhoward@AVALON.NET>
Subject: Re: Running/Outputting t-test results repeatedly
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
Eduardo,
Here's a more complete example:
data test;
infile cards missover;
input d1 d2 v1 v2;
cards;
1 0 30 20
1 0 29 19
1 0 28 18
0 1 40 20
0 1 41 41
0 1 43 33
;
run;
data dependent_vars;
informat varname $30.;
infile cards missover;
input varname;
obsnum + 1;
cards;
d1
d2
;
run;
ods output position=position;
proc contents varnum data=test;
run;
proc sql noprint;
create table independent_vars as
select variable as varname
from position
where variable not in ('d1','d2');
quit;
data independent_vars;
set independent_vars;
obsnum + 1;
run;
%macro get_results(dependent_var, independent_var);
ods trace on;
proc datasets library=work;
delete ttests equality;
quit;
ods output TTests=ttests Equality=equality;
proc ttest data=test;
class &dependent_var;
var &independent_var;
run;
%let probt=.;
proc sql noprint;
select Probt into :probt
from ttests where variances='Equal';
quit;
%put probt= &probt;
%let probf=.;
proc sql noprint;
select Probf into :probf
from equality where method='Folded F';
quit;
%put probf= &probf;
data results;
dependent_var="&dependent_var";
independent_var="&independent_var";
probt=&probt;
probf=&probf;
run;
data allset;
set allset results;
run;
%mend get_results;
%macro do_calls;
data allset;
stop;
run;
proc sql noprint;
select count(*) as dep_count into :dependant_count
from dependent_vars;
quit;
%put &dependant_count;
proc sql noprint;
select count(*) as dep_count into :independant_count
from independent_vars;
quit;
%put &independant_count;
%do i=1 %to &dependant_count;
%do j=1 %to &independant_count;
proc sql noprint;
select varname into :dependent_var
from dependent_vars
where obsnum =&i;
quit;
%put &dependent_var;
proc sql noprint;
select varname into :independent_var
from independent_vars
where obsnum =&j;
quit;
%put &independent_var;
%get_results(&dependent_var,&independent_var);
%end;
%end;
%mend do_calls;
%do_calls;
-Mary
----- Original Message -----
From: "Eduardo Galvan" <EGalvan@SURVEYSCIENCES.COM>
To: <SAS-L@LISTSERV.UGA.EDU>
Sent: Monday, March 30, 2009 10:13 AM
Subject: Running/Outputting t-test results repeatedly
Hi,
Sorry for the repost, but I'm hoping somebody can help me with this. I
have 10 dependent variables (e.g., dv1, dv2,....dv10) that I want run
t-tests on and output the mean, standard deviation, and p-value to a
data file. The catch is that I have over 2,000 variables that I want to
use as the independent variable when I am running these tests. In
other words, I need to run 2,000 t-tests on dv1, 2,000 t-tests on dv2,
etc.
Suggestions are appreciated.
Eduardo