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

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_1Group_2treatmentfrequency
120210103
120210112
1202102 1
120210201
2202102 3
220210201
320210104
320210113
3202102 6
320210205
320210211
420210102
420210111
420210201

 

Want:

GroupGroup_2total_frequencytreatment
120210152
12021022 
22021013 
22021021 
320210171
3202102121
420210131
42021021 

 

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
What is the rule for treatment=1?
COUNT(TREATMENT=1) may be what you need but it doesn't seem to match your input/output - ie GROUP=1 and GROUP2= 202101 has only one treatment=1 but you have a value of 2 in the table.

The next row has one 0 and that isn't counted so you're not counting the presence of values or the values that equal 1 given what you've posted here.

View solution in original post

2 REPLIES 2
Reeza
Super User
What is the rule for treatment=1?
COUNT(TREATMENT=1) may be what you need but it doesn't seem to match your input/output - ie GROUP=1 and GROUP2= 202101 has only one treatment=1 but you have a value of 2 in the table.

The next row has one 0 and that isn't counted so you're not counting the presence of values or the values that equal 1 given what you've posted here.
Reeza
Super User
FYI - you have several questions posted and none are marked as solved. Please mark your questions as solved once you have a solution that works for you.

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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