BookmarkSubscribeRSS Feed
JackZ295
Pyrite | Level 9

I am trying to find the total frequency of a response across several variables. In my example, I have the following 11 categorical variables: 

 

A1Q1, A2Q1, RFQ1, SE1Q1, SE2Q1, SE3Q1, SE4Q1, I1Q1, I2Q1, I3Q1, I4Q1

 

The possible responses for each of the variables is . (Missing), 0, 1, 2, 3, 4, and 5. I want to find the mode response, or the response that respondents pick across all eleven variables. I realize that I cannot use proc univariate, as these variables are not continuous; they are categorical. 

 

Proc freq is not useful, as it presents all of the variables individually, and the frequency of a response (., 0, 1, 2, 3, 4, 5) for that particular variable, not the frequency of the response across all eleven variables (a total frequency). 

 

I tried to use proc tabulate using this code: 

 

proc tabulate data=six;
class A1Q1 A2Q1 RFQ1 SE1Q1 SE2Q1 SE3Q1 SE4Q1 I1Q1 I2Q1 I3Q1 I4Q1;
table A1Q1 A2Q1 RFQ1 SE1Q1 SE2Q1 SE3Q1 SE4Q1 I1Q1 I2Q1 I3Q1 I4Q1;
run;

 

However, this code just provides all of the proc freq tables squished into one. I have attached a photo of the truncated table to show what I mean. Is there any way for me to find the total number of missing responses, responses for 1, responses for 2, responses for 3, responses for 4, and responses for 5 across all eleven variables so that I do not manually have to sum up the frequency for a particular response of each of the variables? Thanks! 

 

tabulate.PNG

 

 

1 REPLY 1
ballardw
Super User

I can think of at least two different interpretations of "I want to find the mode response, or the response that respondents pick across all eleven variables." without even thinking hard.

 

You need to provide some actual example data and the desired result for that data. Likely an example with only 5 variables to reduce the scale would suffice but enough records to work with. The desired result should match the example data exactly.

 

Best is to provide the data in the form of a data step so we can test code. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Proc Tabulate isn't going to work, at least not with out a lot of preprocessing because is only reports on statistics for single variables.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 691 views
  • 0 likes
  • 2 in conversation