Hi!
I have somewhat of a problem that I could not find a solution for.
I want to filter out datalines where variable A is not unique for any different variable B and C combination so that only one dataline remain.
A B C
1 2 3 5
2 2 3 5
3 2 4 5
4 2 5 4
5 3 1 2
6 3 2 1
7 3 1 2
to
A B C
1 2 3 5
2 2 4 5
3 2 5 4
4 3 1 2
5 3 2 1
I would much apreciate any help!
Hi @Viktoreli ,
You can try this::
data have;
input A B C;
cards;
2 3 5
2 3 5
2 4 5
2 5 4
3 1 2
3 2 1
3 1 2
;
run;
proc sort data=have;
by A B C;
run;
data want;
set have;
by A B C;
if first.C then output;
run;
data have;
input A:8. B:8. C:8.;
datalines;
2 3 5
2 3 5
2 4 5
2 5 4
3 1 2
3 2 1
3 1 2
;
run;
proc sort data=have nodupkey out=want;
by a b c;
run;
Hi @Viktoreli ,
You can try this::
data have;
input A B C;
cards;
2 3 5
2 3 5
2 4 5
2 5 4
3 1 2
3 2 1
3 1 2
;
run;
proc sort data=have;
by A B C;
run;
data want;
set have;
by A B C;
if first.C then output;
run;
The simplest way:
proc sort
data=have
out=want
nodupkey
;
by a b c;
run;
And the SQL version:
proc sql;
create table want as
select distinct *
from have;
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 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.