BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Vibcom
Fluorite | Level 6

I have  a dataset with 3 columns . For ex-- 

 

Id CustomerName  TransactionDate 

1   Mayank                  10 aug 2018

 2  Mayank                   11 aug 2018

 3 Akhil                          10 aug 2018

 4 Neha                        20 aug 2018

 5 Abhi                          23 aug 2018

 6 Neha                        30 may 2017

 

I want to create dataset with datasteps from this dataset where customer has done multiple transaction like (Mayank , Neha) but not (AKhil , Abhi).

So Result should be--

Id CustomerName  TransactionDate 

 1   Mayank                  10 aug 2018

 2  Mayank                   11 aug 2018

 4 Neha                        20 aug 2018

 6 Neha                        30 may 2017

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Use PROC SORT to re-order the observations:

 

proc sort data=have;

   by CustomerName;

run;

 

Then you can select those with more than one observation:

 

data want;

   set have;

   by CustomerName;

   if first.CustomerName=1 and last.CustomerName=1 then delete;

run;

 

There are ways to do this in one step with PROC SQL, but I'm more familiar with a DATA step.

View solution in original post

6 REPLIES 6
ballardw
Super User

Is there a rule for excluding the record or just a few specific ones you don't want.

If just a few specific are to be removed or ignored

data want;
   set have 
   if customername not in ('Akhil' 'Abhi');
run;
Vibcom
Fluorite | Level 6
it is not specific for some names..
Astounding
PROC Star

Use PROC SORT to re-order the observations:

 

proc sort data=have;

   by CustomerName;

run;

 

Then you can select those with more than one observation:

 

data want;

   set have;

   by CustomerName;

   if first.CustomerName=1 and last.CustomerName=1 then delete;

run;

 

There are ways to do this in one step with PROC SQL, but I'm more familiar with a DATA step.

Vibcom
Fluorite | Level 6
Thanks. It solved the problem.
shenghuani
Fluorite | Level 6

PROC SQL;

create table data_set_new as

SELECT id, CustomerName,TransactionDate , COUNT(1) AS Cnt
FROM data_set
GROUP BY CustomerName 
HAVING Cnt > 1
ORDER BY Cnt DESC;

QUIT;

Vibcom
Fluorite | Level 6
Thanks ...your solution also can work.

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
  • 6 replies
  • 2013 views
  • 1 like
  • 4 in conversation