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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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.

abudyak
Calcite | Level 5

@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...

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 478 views
  • 1 like
  • 2 in conversation