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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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