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

I have the following dataset

ID

Yes_no

Group_1

Group_2

13

1

1

2

212

0

2

1

212

1

2

3

412

1

0

3

534

0

3

1

 

What I would like to add total_participants in the last column that needs to be static. For example, there are 5 records but only 4 unique ID so I need total_participants = 4. Something like this below:

IDYes_noGroup_1Group_2total_participants
131124
2120214
2121234
4121034
5340314

 

I have no idea how to do this

 

I tried data want; set have;

total_participants = count(ID);

run;

1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ

This is a PROC SQL solution that avoids the warning telling you that it requires remerging summary statistics:

 

proc sql;
	select
				id,
				yes_no,
				group_1,
				group_2,
				(	select
								count(distinct id) as id_count
					from
								have	) as total_participants
	from
				have;
quit;

View solution in original post

1 REPLY 1
maguiremq
SAS Super FREQ

This is a PROC SQL solution that avoids the warning telling you that it requires remerging summary statistics:

 

proc sql;
	select
				id,
				yes_no,
				group_1,
				group_2,
				(	select
								count(distinct id) as id_count
					from
								have	) as total_participants
	from
				have;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 623 views
  • 0 likes
  • 2 in conversation