I need help writting my code correctly as a two sample t test (proc ttest). The way I have it right now it has an error and my professor wants us to write the code using proc ttest, but I am not sure how.
My code:
data name;
input one two @@;
cards;
16.03 16.02 16.04 15.97 16.05 15.96 16.05 16.01 16.02 15.99
16.01 16.03 15.96 16.04 15.98 16.02 16.02 16.01 15.99 16.00
;
proc ttest data=name;
class one;
var two;
run;
So read them the value one by one and toggle the group counter between two different values.
For example you could just do :
data have ;
do group=1,2 ;
input value @@ ;
output;
end;
cards;
10 20 30 40
;
proc ttest data=have;
class group;
var value;
run;
So the DO loop says to set GROUP=1 , then read a value using the double @@ to hold the line so next read starts where this one ended. Then it uses the OUTPUT statement to write an observation. Then the DO loop will set GROUP=2 and do it again. This will continue until it runs out of data to read. Now you have a dataset with two variable GROUP with values 1 and 2 and VALUE with the numbers read from the data lines.
Just replace my dummy data with your data and run it.
Re posting the exact same question does not change the answers you will get.
Provide more details on what you tried based on the responses to your earlier question.
Also please EXPLAIN what your two rows of data mean. Right now you are reading the as alternating between two variables named ONE and TWO.
If you want to run a TTEST you need to groups. Let's call those two groups A and B. Is your data really in the order
A B A B A B A B A B A B A B A B A B A B
So you want to compare the even numbered values to the odd numbered values.
Or is the data really in this order:
A A A A A A A A A A B B B B B B B B B B
So that you want to test if the values in the first line are different than the values in second line.
@Tom I understand what you were saying in the other post, but I am still struggling with writing code because I have never used sas before or any program really and now it is being used in my math class.
The data order is :
A B A B A B...
A B A B A B...
So read them the value one by one and toggle the group counter between two different values.
For example you could just do :
data have ;
do group=1,2 ;
input value @@ ;
output;
end;
cards;
10 20 30 40
;
proc ttest data=have;
class group;
var value;
run;
So the DO loop says to set GROUP=1 , then read a value using the double @@ to hold the line so next read starts where this one ended. Then it uses the OUTPUT statement to write an observation. Then the DO loop will set GROUP=2 and do it again. This will continue until it runs out of data to read. Now you have a dataset with two variable GROUP with values 1 and 2 and VALUE with the numbers read from the data lines.
Just replace my dummy data with your data and run it.
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.