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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.