BookmarkSubscribeRSS Feed
Xinhui
Obsidian | Level 7

Hi There

I have a dummy variable "d" and another variable "csrp"

I want use the paired T test to examine, the "csrp" is significant different between "0" and "1" group of "d'.

How should I code it?

Thanks in advance.

 

 

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @Xinhui 

 

The following code would perform a t-test (mean comparison of two groups defined by the CLASS statement)

proc ttest data=have;
	var csrp;
	class d; 
run;

Are you sure you want to perform a paired t-test? In this case, you need to define the couple of observations between the two groups. Do you have an ID variable to identify pairs?

In this case, you should have two variables (csrp value for each group; a pair by row) and the syntax would be:

proc ttest data=have;
	paired csrp1*csrp2;
run;
DrAbhijeetSafai
Lapis Lazuli | Level 10

This was very useful @ed_sas_member , many thanks!

 

- Dr. Abhijeet Safai

Dr. Abhijeet Safai
Certified Base and Clinical SAS Programmer
Associate Data Analyst
Actu-Real
Reeza
Super User

You need to restructure your data so that SAS knows which pairs go together. That means you need your data in a format like this:

 

ID    Pre    Post
1      5        8
2      4        8
3      6        7
....

You can use PROC TRANSPOSE to restructure your data and then run PROC TTEST as indicated by others.

 

Here's a tutorial on transposing from a long data set to a wide data set with examples that should get you started.
Long to Wide:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/


@Xinhui wrote:

Hi There

I have a dummy variable "d" and another variable "csrp"

I want use the paired T test to examine, the "csrp" is significant different between "0" and "1" group of "d'.

How should I code it?

Thanks in advance.

 

 





hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 3206 views
  • 1 like
  • 5 in conversation