BookmarkSubscribeRSS Feed
xeonchenzi
Calcite | Level 5

Hi,

 

I have a problem to create cross table for survey data contained "select all that applied" questions. The data is like below (Headache and Insomnia are two options in one "select all that applied" questions, so they may overlapped):

 

IDTreatmentHeadacheInsomnia
1100
2010
3110
4110
5110
6000
7111
8110
9010
10110
11111
12110
13010
14000
15100
16110
17101
18110
19110
20110

 

The usual cross table is var by Headache or var by Insomnia separately with (0,1)x(0,1).

But I wonder how I can get a cross table crossing all options = 1 together, like the following table:

 

Treatment

Headache=1 [N (%)]

Insomnia=1 [N (%)]

1

xx (a%)

xx (b%)

0

xx (c%)

xx (d%)

Total

n_1 (100%)

n_2 (100%)

In this case, only a+c=100% make sense.

 

For the completeness, I also wonder how to get a "transposed" table like:

 

Treatment

 

 

 

1  [N (%)]

0 [N (%)]

Total

Headache=1

xx (a%)

xx (b%)

n_1 (100%)

Insomnia=1

xx (c%)

xx (d%)

n_2 (100%)

In this case, of course only a+b=100% make sense.

 

Hope someone could help. Thanks so much!

1 REPLY 1
Reeza
Super User

Have you tried PROC MEANS?

 

proc means data=have noprint;
class treatment; 
ways 0 1;
output out = want sum= N mean = PCT; 
run;

With 0/1 variables if you take the sum that's the equivalent of counting the number of 1s. If you take the mean, that's the same as calculating the percent. 

The CLASS statement tells SAS to calculate it by treatment. 

WAYS tells it to do the total and one way summaries. 

WANT data set will have everything you need to create your table and then you'll need to figure out how to display it. 

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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