Hi!
I have a dataset where I would like to count the number of times different values of a variable occurs but only once for every Id.
ID Variable
1 A
2 B
3 B
4 A
5 A
1 A
1 B
3 B
4 B
I want this as a result:
Count_A Count_B
3 4
If ID 1 have A twice I only want it to count as one.
Thanks! I didn't quite work.
I used the following code (as I also had to group by other variable)
proc sql;
create table want as
select
year, variable, count(distinct ID)
from data
group by
year, variable
;
quit;
proc sql;
create table want as
select count(distinct id) as Count_A,
count(distinct Variable) as Count_B
from have;
quit;
Thanks! I didn't quite work.
I used the following code (as I also had to group by other variable)
proc sql;
create table want as
select
year, variable, count(distinct ID)
from data
group by
year, variable
;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: