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

Hi, I am trying to create a 2x2 table and gather chisq. However, my treatment variable is by default showing up as 2 then 1 but i wanted it in ascending (1 then 2). My response variable is outputting correctly (1 then 0).

 

Here is my code:

 

PROC SORT data = dtanl.hivcancerdta;
by descending cancer;
RUN;

 

PROC FREQ data = dtanl.hivcancerdta order = data;
TABLE alcoh*cancer / chisq riskdiff or;
WHERE alcoh ^= 9;
RUN;

 

My output is:

 

2x2.PNG

Any information on what i am doing wrong would be appreciated!

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @pramenon1,

 

Add alcoh to the BY statement of the PROC SORT step:

by alcoh descending cancer;

Then your existing ORDER=DATA will sort rows and columns of the frequency table as desired.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Use ORDER=INTERNAL

--
Paige Miller
pramenon1
Obsidian | Level 7

When I do that, cancer reverts to 0 then 1. I need it to be 1 then 0.

FreelanceReinh
Jade | Level 19

Hi @pramenon1,

 

Add alcoh to the BY statement of the PROC SORT step:

by alcoh descending cancer;

Then your existing ORDER=DATA will sort rows and columns of the frequency table as desired.

pramenon1
Obsidian | Level 7
Thank you! This worked perfectly!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1072 views
  • 2 likes
  • 3 in conversation