Using the dataset below, what I would like is to create total counts by each group_1 and group_2 for frequency and treatment=1 by group_1 group 2
| Group_1 | Group_2 | treatment | frequency |
| 1 | 202101 | 0 | 3 |
| 1 | 202101 | 1 | 2 |
| 1 | 202102 | 1 | |
| 1 | 202102 | 0 | 1 |
| 2 | 202102 | 3 | |
| 2 | 202102 | 0 | 1 |
| 3 | 202101 | 0 | 4 |
| 3 | 202101 | 1 | 3 |
| 3 | 202102 | 6 | |
| 3 | 202102 | 0 | 5 |
| 3 | 202102 | 1 | 1 |
| 4 | 202101 | 0 | 2 |
| 4 | 202101 | 1 | 1 |
| 4 | 202102 | 0 | 1 |
Want:
| Group | Group_2 | total_frequency | treatment |
| 1 | 202101 | 5 | 2 |
| 1 | 202102 | 2 | |
| 2 | 202101 | 3 | |
| 2 | 202102 | 1 | |
| 3 | 202101 | 7 | 1 |
| 3 | 202102 | 12 | 1 |
| 4 | 202101 | 3 | 1 |
| 4 | 202102 | 1 |
I tried the following
proc sql;
select distinct group_1, group_2, sum(frequency) as total_frequency, sum(treatment) as treatment //not sure how to add treatment= 1
from have;
group by group_1, group_2;
quit;
quit;
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.