Help using Base SAS procedures

Need frequency matrix using proc freq

Reply
Super Contributor
Posts: 266

Need frequency matrix using proc freq

Hi All,

 

I need frequency matrix of my data.

 

my data is having 3 question Q1 -- Q23 and and one variable is cluster

value of cluster is 1 to 3

and values of Q1--Q23 are 1 to 5

i am using code below:

 


proc freq data=out_3 ;
table (Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15 Q16 Q17 Q18 Q19 Q20 Q21 Q22 Q23)*cluster
/nocol norow nocum nopercent;
run;

OUTPUT:

 

Q23 CLUSTER COUNT PERCENT
1        1               68          0.3046322014
1        2               698        3.1269599498
1        3               3310     14.828420392
2        1               213       0.9542155721
2        2               2114      9.4704775558
2        3               3598     16.118627363
3        1               1323      5.9268882717
3        2               4657      20.862825912
3        3               1015      4.5470835947
4       1                3314      14.846339934
4       2                1385      6.2046411612
4       3                42          0.1881551832
5      1                 472        2.1145058686
5      2                103        0.4614281874
5      3                10          0.0447988531

 

 

Now problem is , i am getting output only for Q23 , but i am looking result for all Q1--23 .

 

Is it possible to get that.

 

Thanks in advance

Super User
Posts: 7,758

Re: Need frequency matrix using proc freq

[ Edited ]

Could you please supply some test data in a data step (w/ cards) so we have something to chew on?

 

PS you added "nopercent" for the tables, yet your example output shows a percent column.

Are you sure this is the output of your code?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,018

Re: Need frequency matrix using proc freq


proc freq data=out_3 ;
table (Q1-Q23)*cluster
/nocol norow nocum nopercent list out=want ;
run;
Super User
Super User
Posts: 7,942

Re: Need frequency matrix using proc freq

Out of interest, does the : work there also?:

proc freq data=out_3;
  table (Q:)*cluster /nocol norow nocum nopercent list out=want;
run;

 

Community Manager
Posts: 2,951

Re: Need frequency matrix using proc freq

Yes, @RW9, the colon notation works in this case too.  At least within SAS 9.3 and later, where I tested.


Example:

proc freq data=sashelp.baseball;
 table (D:)*position;
run;

Matches DIVISION and DIV (two different fields).

Super Contributor
Posts: 266

Re: Need frequency matrix using proc freq

sir i have already run these code, but in output want , i m getting only result for Q23. please check the output.

Super User
Posts: 7,758

Re: Need frequency matrix using proc freq

Read the documentation. And I mean it.

Only the last table will end up in the output dataset. SAS works as documented in this case.

Try transposing your dataset, so that you can use question number as a by variable.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,758

Re: Need frequency matrix using proc freq

I guess you just need to read the documentation thoroughly

From PROC FREQ - TABLES Statement:

OUT=SAS-data-set

names an output data set that contains frequency or crosstabulation table counts and percentages. If more than one table request appears in the TABLES statement, the contents of the OUT= data set correspond to the last table request in the TABLES statement.

(Underline added by me)

 

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,018

Re: Need frequency matrix using proc freq

ods output list=want;
proc freq data=out_3 ;
table (Q1-Q23)*cluster
/nocol norow nocum nopercent list ;
run;
Ask a Question
Discussion stats
  • 8 replies
  • 400 views
  • 4 likes
  • 5 in conversation