BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi,

I have a data

id  a  b 

1   1  2

2   .    .

3   1   3

4   .     .

5   .     .

 

In the above data I have "a" has duplicate. So. I want take the second duplicate value "b" to the first.

Also the missing values should be deleted if it is in between the duplicates. If the missing values are not between, then I want to take only one and not the duplicate missing value.

want data:

id a  b

1  1  3

4  .    .

 

2 REPLIES 2
Shmuel
Garnet | Level 18

What does ID mean? It seems you assigned it just the observation number and it can be neglected and dropped?

 

If you drop ID, sort the data by a then select last.a - maybe you will get what you want.

Ksharp
Super User
data have;
input id  a  b ;
cards;
1   1  2
2   .    .
3   1   3
4   .     .
5   .     .
;

data temp;
 set have end=last;
 by id a b notsorted;
 if cmiss(a,b)=2 and not last then delete;
run;
data want;
 set temp;
 by a notsorted;
 if last.a;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 497 views
  • 0 likes
  • 3 in conversation