Hi,
I have the following data:
| customer_id | customer_name | visit |
| 456A | John | 1 |
| 123B | Smith | 3 |
| 123B | Smith | 4 |
| 987D | David | 2 |
| 654H | Haydar | 4 |
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_id | customer_name | visit |
| 456A | John | 1 |
| 123B | Smith | 3 |
| 987D | David | 2 |
| 654H | Haydar | 4 |
Thanks
data want;
set have;
by customer_id customer_name notsorted;
if first.customer_id and first.customer_name;
run;
@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.
Oh yes of course. Thank you
I need to keep the first observation of the same customer_id and customer_name
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.