Hello
I am using proc freq to create 2 way freq table.
The problem is that I want to control the following issues:
1-Order of rows will be by the total freq of each category of field Z2
2-Order of columns will be be order of numbers in field Z1: 2 3 4 5 6
When I use order=freq then order of rows is correct but order of columns (Z2 categories) is not as I want
data rawdata;
input ID Z1 Z2 $;
cards;
1 2 xjfjjj
2 3 djdjdj
3 3 xjfjjj
4 4 djdjdj
5 5 xjfjjj
6 5 djdjdj
7 6 djdjdj
8 6 asasas
9 6 asasas
10 6 djdjdj
;
run;
PROC FREQ DATA=rawdata order=freq ;
TABLE Z2* Z1/ MISSING NOPERCENT NOCOL norow ;
RUN;
data rawdata;
input ID Z1 Z2 $;
cards;
1 2 xjfjjj
2 3 djdjdj
3 3 xjfjjj
4 4 djdjdj
5 5 xjfjjj
6 5 djdjdj
7 6 djdjdj
8 6 asasas
9 6 asasas
10 6 djdjdj
;
run;
PROC tabulate DATA=rawdata ;
class z2/order=freq;
class z1/order=internal;
TABLE z2=' ' all,z1*n*f=8.0 all*n*f=8.0/printmiss box='z2' misstext='0';
keylabel n=' ';
RUN;
data rawdata;
input ID Z1 Z2 $;
cards;
1 2 xjfjjj
2 3 djdjdj
3 3 xjfjjj
4 4 djdjdj
5 5 xjfjjj
6 5 djdjdj
7 6 djdjdj
8 6 asasas
9 6 asasas
10 6 djdjdj
;
run;
PROC tabulate DATA=rawdata ;
class z2/order=freq;
class z1/order=internal;
TABLE z2=' ' all,z1*n*f=8.0 all*n*f=8.0/printmiss box='z2' misstext='0';
keylabel n=' ';
RUN;
It is perfect and thank you for the solution.
I want to ask please what is the way to do it via proc freq.
When I use "order=freq " then I control the order of the rows but why the order of the columns(Var Z1) is changed?
I think it is hard for PROC FREQ . Maybe somebody could shed a light .
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.