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

Hello, I am fairly new to the SAS environment and I am now stuck and having some issues using PROC FREQ to aggregate my data by response patterns. I have over 30,000 observations and about 10 variables I would like to aggregate. As an example... my individual response data looks like Table 1 and would like to aggregate the patterns of response to look like Table 2. Thanks for your help!

 

Table 1

Do you drink…..everyday ? 1 = Yes 2 = No
IDTeaCoffeeJuice WineBeerWater
1121212
2212121
3212121
4121212
5111111
6111111
7222221
8222221
9222221
10111111

 

 

Table 2 

 

Patterns of response 
 TeaCoffee  JuiceWine  BeerWater Count (total number of participants with that pattern of response to all the variables)
1212122
2121212
1111113
2222223
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use PROC FREQ. You may want to consider switching 2 to 0, it makes things easier if you want to do any math. Then you can just use functions.

Ie # of type drinks a person has a day = sum(of tea -- water);

What percent of people had each drink? Proc MEANS. Otherwise you're stuck with do loops and proc freqs.

 

 

 

proc freq data=table1 NOPRINT;
table tea*coffee*juice*wine*beer / out=patterns; 
run;

@estherism wrote:

Hello, I am fairly new to the SAS environment and I am now stuck and having some issues using PROC FREQ to aggregate my data by response patterns. I have over 30,000 observations and about 10 variables I would like to aggregate. As an example... my individual response data looks like Table 1 and would like to aggregate the patterns of response to look like Table 2. Thanks for your help!

 

Table 1

Do you drink…..everyday ? 1 = Yes 2 = No
ID Tea Coffee Juice  Wine Beer Water
1 1 2 1 2 1 2
2 2 1 2 1 2 1
3 2 1 2 1 2 1
4 1 2 1 2 1 2
5 1 1 1 1 1 1
6 1 1 1 1 1 1
7 2 2 2 2 2 1
8 2 2 2 2 2 1
9 2 2 2 2 2 1
10 1 1 1 1 1 1

 

 

Table 2 

 

Patterns of response  
 Tea Coffee   Juice Wine   Beer Water  Count (total number of participants with that pattern of response to all the variables)
1 2 1 2 1 2 2
2 1 2 1 2 1 2
1 1 1 1 1 1 3
2 2 2 2 2 2 3

 

View solution in original post

2 REPLIES 2
Reeza
Super User

Use PROC FREQ. You may want to consider switching 2 to 0, it makes things easier if you want to do any math. Then you can just use functions.

Ie # of type drinks a person has a day = sum(of tea -- water);

What percent of people had each drink? Proc MEANS. Otherwise you're stuck with do loops and proc freqs.

 

 

 

proc freq data=table1 NOPRINT;
table tea*coffee*juice*wine*beer / out=patterns; 
run;

@estherism wrote:

Hello, I am fairly new to the SAS environment and I am now stuck and having some issues using PROC FREQ to aggregate my data by response patterns. I have over 30,000 observations and about 10 variables I would like to aggregate. As an example... my individual response data looks like Table 1 and would like to aggregate the patterns of response to look like Table 2. Thanks for your help!

 

Table 1

Do you drink…..everyday ? 1 = Yes 2 = No
ID Tea Coffee Juice  Wine Beer Water
1 1 2 1 2 1 2
2 2 1 2 1 2 1
3 2 1 2 1 2 1
4 1 2 1 2 1 2
5 1 1 1 1 1 1
6 1 1 1 1 1 1
7 2 2 2 2 2 1
8 2 2 2 2 2 1
9 2 2 2 2 2 1
10 1 1 1 1 1 1

 

 

Table 2 

 

Patterns of response  
 Tea Coffee   Juice Wine   Beer Water  Count (total number of participants with that pattern of response to all the variables)
1 2 1 2 1 2 2
2 1 2 1 2 1 2
1 1 1 1 1 1 3
2 2 2 2 2 2 3

 

estherism
Calcite | Level 5

Great thank you, this pretty much worked for what I needed! 

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1059 views
  • 0 likes
  • 2 in conversation