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:
ID | Yes_no | Group_1 | Group_2 | total_participants |
13 | 1 | 1 | 2 | 4 |
212 | 0 | 2 | 1 | 4 |
212 | 1 | 2 | 3 | 4 |
412 | 1 | 0 | 3 | 4 |
534 | 0 | 3 | 1 | 4 |
I have no idea how to do this
I tried data want; set have;
total_participants = count(ID);
run;
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;
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;
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.