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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
SLK
Obsidian | Level 7 SLK
Obsidian | Level 7

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;

View solution in original post

2 REPLIES 2
Madansas7b
Obsidian | Level 7

proc sql;

create table want as

select count(distinct id) as Count_A,

count(distinct  Variable) as Count_B

from have;

quit;

SLK
Obsidian | Level 7 SLK
Obsidian | Level 7

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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