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 |
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
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
Great thank you, this pretty much worked for what I needed!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.