BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Madhu6
Calcite | Level 5

Hello Everyone,                                                                       

 

Thank you for reading this post. 

I am using SAS9.4

I need help with creating the ttest table that should exactly look like this:

T-Tests

Variable

Method

Variances

DF

t Value

Pr > |t|

mean

Pooled

Equal

XX

XX

XX

mean

Satterthwaite

Unequal

XX

XX

XX

 

I have two similar-looking tables: Table 1 and Table 2:

data table1;
input day0 day3 day7 day14 day30;
datalines;
8.5 7.2 9.5 10.2 10.6
4 5 6 6 6
9 8 7 5 6
8.5 6.4 9.3 10.8 11
8.7 7.8 10.3 12 9
5 9.7 3 4 5.5
run;

 

data table2;
input day0 day3 day7 day14 day30;
datalines;
6.5 7.2 5.5 8.2 4.6
6 5 9 4 8
3 8 9 5 4
6.5 8.4 5.3 12.8 10
6.7 7.8 9.3 4 5.3
5.2 8.7 3 4 5.5

run;

 

I used the following code and got ttest table:

 

proc means data = table1 noprint;
output out = a(drop = _type_ _freq_ );
run;
proc transpose data = a out = a (drop = n min max std ) ;
id _STAT_;
run;

proc means data = table2 noprint;
output out = b(drop = _type_ _freq_ );
run;

proc transpose data = b out = b (drop = n min max std ) ;
id _STAT_;
run;

data combo_a;
set a ;
_name_ = 'mean_a';
run;
data combo_b;
set b ;
_name_ = 'mean_b';
run;
data combo;
set combo_a combo_b;
run;
proc means data=combo noprint;
var mean;
by _name_;
output out=new_combo;
run;
proc ttest data=new_combo nobyvar;
class _name_;
var mean;
run;

 

Thank you,

Madhu

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

First a syntax reminder: The DATALINES or CARDS block ends with a semicolon on a separate line from the last data to read.

 

For the forum it is good idea to paste code or log entries into a text box opened with the </> icon that appears above the message window. Pasting code into the main message window on the forum may result in code that runs incorrectly as the forum software reformats pasted text.

 

Are you asking how to get a second row label of Mean displayed? Or a title of 'T-Tests' displayed before the output?

You can capture the data from the test summary by adding ODS OUTPUT to your code and then you have a data set that you can use for any manipulation for a report or data step manipulation:

ods output ttests= testoutput;
proc ttest data=new_combo nobyvar;
   class _name_;
   var mean;
run;

For example creates a data set Testoutput from your example that could be used to make that appearance. I'm just not sure exactly what is missing. Note that table does have the variable name on each row.

 

Lastly, I  think your approach may be suspect. You summarize and discard variability information, summarize a second time, again discarding variability information and the perform the t-test. Note that the N of your example in the T-test summary is 5. What exactly is the test supposed to be testing?

View solution in original post

2 REPLIES 2
ballardw
Super User

First a syntax reminder: The DATALINES or CARDS block ends with a semicolon on a separate line from the last data to read.

 

For the forum it is good idea to paste code or log entries into a text box opened with the </> icon that appears above the message window. Pasting code into the main message window on the forum may result in code that runs incorrectly as the forum software reformats pasted text.

 

Are you asking how to get a second row label of Mean displayed? Or a title of 'T-Tests' displayed before the output?

You can capture the data from the test summary by adding ODS OUTPUT to your code and then you have a data set that you can use for any manipulation for a report or data step manipulation:

ods output ttests= testoutput;
proc ttest data=new_combo nobyvar;
   class _name_;
   var mean;
run;

For example creates a data set Testoutput from your example that could be used to make that appearance. I'm just not sure exactly what is missing. Note that table does have the variable name on each row.

 

Lastly, I  think your approach may be suspect. You summarize and discard variability information, summarize a second time, again discarding variability information and the perform the t-test. Note that the N of your example in the T-test summary is 5. What exactly is the test supposed to be testing?

Madhu6
Calcite | Level 5

Hello ballardw,

 

Thank you for your detailed response and for telling me about the </> icon. 

 

I have two datasets Pr_table5 (test) and C_table5 (control).

Each table consists of CD3 tested on different time intervals (day 0 day3 day7 day14 day30) with different n on each day. For example, day0 N is 63, and day30 N is 50

 

I have to calculate a t-test comparing Pr_table5 and C_table5. The final table should look like this:-

T-Tests

Variable

Method

Variances

DF

t Value

Pr > |t|

mean

Pooled

Equal

XX

XX

XX

mean

Satterthwaite

Unequal

XX

XX

XX

 

So I calculated the mean for Pr_table5 (mean of day0, mean of day3...) and c_table5  (mean of day0, mean of day3...) and dropped n min max std so that it will have only mean from table1 and table 2.

 

proc means data = Pr_table5 noprint;
output out = a(drop = _type_ _freq_ );
run;
proc transpose data = a out = a (drop  = n min max std ) ;
id _STAT_;
run;

proc means data = c_table5 noprint;
output out = b(drop = _type_ _freq_ );
run;

proc transpose data = b out = b (drop  = n min max std ) ;
id _STAT_;
run;

Then I merged two tables  (combo) which contain means from two tables.

data combo_a;
set a ;
_name_ = 'mean_a';
run;
data combo_b;
set b ;
_name_ = 'mean_b';
run;
data combo;
set combo_a combo_b;
run;

Next, I did a t-test

proc means data=combo noprint;
var mean;
by _name_;
output out=new_combo;
run;
proc ttest data=new_combo nobyvar;
class _name_;
var mean;
run;

Please let me know if there is a better approach, from both a statistical and programming point of view.

 

Thank you,
Madhu

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1337 views
  • 0 likes
  • 2 in conversation