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 

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

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