BookmarkSubscribeRSS Feed
SLK
Obsidian | Level 7 SLK
Obsidian | Level 7

Hi,

 

My variables: ID, year, drinks(beer or wine).

 

I want to count distinct ID by the drinks variable: only count the ID-numbers who only drank beer and those who only drank wine. If a person drank both, they should not be in any count.

 

My code:

 

proc sql

create tables want as

select year, drinks, count(distinct ID)

from have

group by year, drinks

exit;

 

This only count distinct within each drink-type: if a person has more than one beer he is only in the count once, but if he also had wine he is also in the count for wine.

 

Hope someone can help me with my problem!!

 

2 REPLIES 2
LinusH
Tourmaline | Level 20

I think this is hard to achieve in a single (non nested) SQL step.

What about if a person drinks beer year 1, and wine year 2?

Data never sleeps
SLK
Obsidian | Level 7 SLK
Obsidian | Level 7

They only have to be unique per year so a person can drink beer one year and wine the other.

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
  • 2436 views
  • 0 likes
  • 2 in conversation