BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nnn123
Fluorite | Level 6

Hi,

 

I'm currently working with some stratified survey data and want to run out big tables of one set of responses versus another. i.e. how did individuals that answered question 1 subsequently answer question 2, question 3, question 4 etc.

 

So far i have got this code running producing exactly what i want in a 'program' sheet within SAS EG:

 

proc surveyfreq data=QUESTION_DATA_AND_STRATA nosummary;

tables Q1 * Q2/ row;
strata LaCode;
weight Q1_Weight;
run;
 
The only limitation to this though is that this only shows question 1 vs question 2 - I am having to copy it each time for each question. How can i put multiple questions in so I get one big table with more manageable results? Either stacked side by side as columns or underneath each other as rows, it doesn't matter to me. I can't get the syntax right (line 2 is the issue), I've been trying things such as these below with no luck:

 

proc surveyfreq data=QUESTION_DATA_AND_STRATA nosummary;

tables Q1 * Q2/ row; tables Q1 * Q3/ row
strata LaCode;
weight Q1_Weight;
run;
 
and 
 

proc surveyfreq data=QUESTION_DATA_AND_STRATA nosummary;

tables Q1 * Q2; Q1 * Q3/ row;
strata LaCode;
weight Q1_Weight;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@nnn123 wrote:

Hi FreelanceReinhard,

 

Thanks for such a quick response! These codes below create a separate table for each question though. I want them all in one big table if at all possible? There are 22 questions in the survey so it would create 21 mini tables otherwise.

 

Is this possible?


It sounds like you need to create an output data set from Surveyfreq and use another report procedure to control appearances.

Adding something like:

ODS OUTPUT crosstabs=mycrosstabs;

would send the output of the crosstab tables requests to a data set you can manipulate or print, though possibly not the prettiest. I find that "pretty" tables require some manipulation of that data set.

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hi @nnn123,

 

Try this:

tables Q1*Q2 Q1*Q3 / row;

Or, equivalently, this:

tables Q1*(Q2 Q3) / row;
nnn123
Fluorite | Level 6

Hi FreelanceReinhard,

 

Thanks for such a quick response! These codes below create a separate table for each question though. I want them all in one big table if at all possible? There are 22 questions in the survey so it would create 21 mini tables otherwise.

 

Is this possible?

FreelanceReinh
Jade | Level 19

@nnn123 wrote:

These codes below create a separate table for each question though.


A TABLES request like Q1*Q2 creates a kind of cross-tabulation for combinations of Q1 and Q2 values, so each of the "separate tables" is for a combination of two questions.

 

Theoretically one could imagine a similar cross-tabulation for a combination of 22 questions (like Q1*Q2*Q3*...*Q22), but in many cases this would be very large, considering that even 22 yes/no questions would have 2**22=4,194,304 possible combinations of answers.

 

Can you outline the layout of your desired "big table"?

ballardw
Super User

@nnn123 wrote:

Hi FreelanceReinhard,

 

Thanks for such a quick response! These codes below create a separate table for each question though. I want them all in one big table if at all possible? There are 22 questions in the survey so it would create 21 mini tables otherwise.

 

Is this possible?


It sounds like you need to create an output data set from Surveyfreq and use another report procedure to control appearances.

Adding something like:

ODS OUTPUT crosstabs=mycrosstabs;

would send the output of the crosstab tables requests to a data set you can manipulate or print, though possibly not the prettiest. I find that "pretty" tables require some manipulation of that data set.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1658 views
  • 0 likes
  • 3 in conversation