SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ritter
Calcite | Level 5

I'm a new user to SAS and I want to figure out how to run a two sample test between two variables in a data set.

 

As I know, the proc T-test can only use class to specify the variable with 2 class to do the 2 sample test, but I want to do 2 sample test between variables.

 

For example;

x  y

1  2

3  4

5  6

 

I want to test the X and Y's means with 2 sample t-test

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Is this supposed to be a Paired ttest where you are looking at the differences between x and y on each row? Such as in a before/after score?

That would be:

data have;
input x  y  ;
datalines;
1  2
3  4
5  6
;
run;

proc ttest data=have;
   paired x*y;
run;

If you are looking for two independent samples then the data would have to be restructured to include a group variable to distinguish between x and y as data source.

View solution in original post

3 REPLIES 3
ballardw
Super User

Is this supposed to be a Paired ttest where you are looking at the differences between x and y on each row? Such as in a before/after score?

That would be:

data have;
input x  y  ;
datalines;
1  2
3  4
5  6
;
run;

proc ttest data=have;
   paired x*y;
run;

If you are looking for two independent samples then the data would have to be restructured to include a group variable to distinguish between x and y as data source.

Ritter
Calcite | Level 5

Thanks for your help !

 

Actually, I want to do the two independent sample test. But I don't know how to merge two variables into one and add their origin name as a new variable in new data set at same time.

 

Could you like show me some code?

 

Thanks

ballardw
Super User

@Ritter wrote:

Thanks for your help !

 

Actually, I want to do the two independent sample test. But I don't know how to merge two variables into one and add their origin name as a new variable in new data set at same time.

 

Could you like show me some code?

 

Thanks


Here's one way to restructure the data for two independent samples.

data have;
input x  y  ;
   Group='X'; Value=x;output;
   Group='Y'; value=y;output;
datalines;
1  2
3  4
5  6
;
run;

proc ttest data=have;
   class group;
   var value;
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4831 views
  • 0 likes
  • 2 in conversation