BookmarkSubscribeRSS Feed
altijani
Quartz | Level 8

Hi,

 

I have the following data:

 

customer_idcustomer_namevisit
456AJohn1
123BSmith3
123BSmith4
987DDavid2
654HHaydar4

 

I need to delete the second row for Smith, because customer_id and customer_name are the same. In other words: only keep the first instance of visit. What I want is like this:

 

customer_idcustomer_namevisit
456AJohn1
123BSmith3
987DDavid2
654HHaydar4

 

Thanks

4 REPLIES 4
novinosrin
Tourmaline | Level 20
data want;
set have;
by  customer_id	customer_name notsorted;
if first.customer_id and first.customer_name;
run;
Tom
Super User Tom
Super User

@novinosrin wrote:
data want;
set have;
by  customer_id	customer_name notsorted;
if first.customer_id and first.customer_name;
run;

You don't need to reference both of those FIRST. variables.   If you want to keep multiple names per CUSTOMER_ID then just use FIRST.CUSTOMER_NAME.  If you just want one name per customer_id the just use use FIRST.CUSTOMER_ID.  Note that FIRST.CUSTOMER_NAME will always be true when FIRST.CUSTOMER_ID is true.

novinosrin
Tourmaline | Level 20

Oh yes of course. Thank you

altijani
Quartz | Level 8

I need to keep the first observation of the same customer_id and customer_name 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1260 views
  • 0 likes
  • 3 in conversation