My data looks like this:
ID Var Value
1 A 1
1 A 1
1 B 2
1 B 3
2 A 4
2 B 5
I would like to output the duplicate observations for ID and Var:
ID Var Value
1 A 1
1 A 1
1 B 2
1 B 3
I've tried this:
proc sql;
create table want as
select distinct id, var, count(*)
from have
group by id, var
having count(*) > 1;
quit;
However, this gives me all the disinct records of id and var, not just the instances where they appear twice or more. It also leaves out the Value column, which I would like to keep:
ID Var
1 A
1 B
1 B
2 A
2 B
Could someone please help me with this? Thanks.
Change your select statement to
select *
from...
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.
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.