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

Hello,

 

This may sound like a very basic question... but,

 

I am working with a set of chemotherapy data that contains 3 types of chemotherapy and it would be really helpful if there is a way to run Chi-Squared Test in SAS without seperating the files.

 

My data and variables looks like the following:

 

Patient_ID=ID assigned to Patient

Chemo_Type=Type of Chemotherapy (1=type A, 2=type B, 3=type C)

Readmiited_YN=Readmission to Hospital after Chemotherapy (1=readmission, 0=no readmission),

 

 

Patient_ID    Chemo_Type   Readmitted_YN

10012                        1                       1

10013                        2                       0

10014                        3                       0

10015                        2                       1

10016                        2                       0

10017                        3                       1

10018                        1                       1

10019                        2                       1

.

.

.

(cont')

 

with this data set I have to do a run a chi-squared test for Chemo_Type=1 vs. Chemo_Type=2 & Chemo_Type=1 vs. Chemo_Type=3 (*I do NOT need to run a chi-squared test for Chemo_type=2 vs. Chemo_type=3)

 

Is there a way to run the chi-squared test for Chemo_Type=1 vs. Chemo_Type=2 & Chemo_Type=1 vs. Chemo_Type=3 with the current data set I have?

 

I am currently doing the following :

 

-------------------------------------------------------------------------------------------

 

data w.cancer_1vs2; set w.cancer; if Chemo_type=3 then delete;

 

proc freq data=w.cancer_1vs2;

tables Chemo_Type*Readmitted_YN/chisq;

run;

 

data w.cancer_1vs3; set w.cancer; if Chemo_type=2 then delete;

 

proc freq data=w.cancer_1vs3;

tables Chemo_Type*Readmitted_YN/chisq;

run;

---------------------------------------------------------------------------------------------

 

Is there a way to run this in a single file (w.cancer) without having to delete the undesired Chemo_Type for running Chi-Squared Test?

 

Thank you.

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Yes. Most Procs support the WHERE statement. 

 

Proc freq data = have;
Where chemo_type ne 3;
Table .../ chisq;
Run;

Proc freq data = have;
Where chemo_type ne 2;
Table ... / chisq;
Run;

View solution in original post

2 REPLIES 2
Reeza
Super User

Yes. Most Procs support the WHERE statement. 

 

Proc freq data = have;
Where chemo_type ne 3;
Table .../ chisq;
Run;

Proc freq data = have;
Where chemo_type ne 2;
Table ... / chisq;
Run;
sasworker16
Calcite | Level 5

Thank you so much for your answer.

 

Your answer was really helpful.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1647 views
  • 0 likes
  • 2 in conversation