BookmarkSubscribeRSS Feed
Aman4SAS
Obsidian | Level 7

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

8 REPLIES 8
Kurt_Bremser
Super User

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?

Ksharp
Super User

proc freq data=out_3 ;
table (Q1-Q23)*cluster
/nocol norow nocum nopercent list out=want ;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

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

 

ChrisHemedinger
Community Manager

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).

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Aman4SAS
Obsidian | Level 7

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

Kurt_Bremser
Super User

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.

Kurt_Bremser
Super User

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)

 

 

Ksharp
Super User
ods output list=want;
proc freq data=out_3 ;
table (Q1-Q23)*cluster
/nocol norow nocum nopercent list ;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 2379 views
  • 4 likes
  • 5 in conversation