Hi All,
I have data like this.
data:
obs | id | a | b | c | d | e |
1 | 1 | 0 | 1 | 0 | 0 | |
2 | 1 | 0 | 1 | 0 | 0.5 | 1 |
3 | 1 | 11.2 | 0 | 5 | 0.5 | 0 |
4 | 1 | 15.9 | 0 | 150 | 0.5 | 0 |
5 | 1 | 13.3 | 0 | 200 | 0.5 | 0 |
6 | 1 | 5 | 1 | 260 | 0.5 | 0 |
7 | 1 | 5 | 1 | 300 | 0.5 | 0 |
8 | 1 | 5 | 1 | 360 | 0.5 | 0 |
want:
obs | id | a | b | c | d | e |
1 | 1 | 0 | 1 | 0 | 0 | |
2 | 1 | 0 | 1 | 0 | 0.5 | 1 |
3 | 1 | 11.2 | 0 | 5 | 0.5 | 0 |
4 | 1 | 15.9 | 0 | 150 | 0.5 | 0 |
5 | 1 | 13.3 | 0 | 200 | 0.5 | 0 |
6 | 1 | 5 | 1 | 260 | 0.5 | 0 |
I want keep only one observation where a=5 and b=1
please let me know how to do this in sas.
Thanks in advance.
2
Answer: the follwing code gives what i want.
Proc sort data= data out= want;
by id a b e;
run;
Thanks forum.
Probably the easiest if the file is not extremely large is
Proc sort data=have out=want noduprecs;
by id;
run;
You may need to post a more complete example if your data is more complex.
1 2 3 4 5
1 2 3 6 6 <only var3 duplicates does this get deleted?>
1 2 3 4 6 <only var3 and var4 duplicate the first, does this get deleted?>
1 2 3 4 5 <all of var3, var 4 and var5 duplicate the first, the original proc sort solution would work>
Answer: the follwing code gives what i want.
Proc sort data= data out= want;
by id a b e;
run;
Thanks forum.
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!
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.