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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 821 views
  • 0 likes
  • 3 in conversation