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:
Any information on what i am doing wrong would be appreciated!
Thanks!
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.
Use ORDER=INTERNAL
When I do that, cancer reverts to 0 then 1. I need it to be 1 then 0.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.