DATA Step, Macro, Functions and more

Is there a way to run multiple Chi-Squared Test in SAS without separating files?

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Is there a way to run multiple Chi-Squared Test in SAS without separating files?

[ Edited ]

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.

 

 

 

 

 

 

 

 

 

 


Accepted Solutions
Solution
‎07-16-2016 08:36 AM
Super User
Posts: 19,822

Re: Is there a way to run multiple Chi-Squared Test in SAS without separating files?

Posted in reply to sasworker16

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


All Replies
Solution
‎07-16-2016 08:36 AM
Super User
Posts: 19,822

Re: Is there a way to run multiple Chi-Squared Test in SAS without separating files?

Posted in reply to sasworker16

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;
Contributor
Posts: 24

Re: Is there a way to run multiple Chi-Squared Test in SAS without separating files?

Thank you so much for your answer.

 

Your answer was really helpful.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 283 views
  • 0 likes
  • 2 in conversation