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 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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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