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;
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.
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.