BookmarkSubscribeRSS Feed
lutherh
Calcite | Level 5

Hi All,

 

I have a dataset with four columns, of which the middle two have character variables from which I would like to delete duplicates. The first column is an identifier column, 'GuestNo'. The second and third columns are character columns listing type of candy bought before and after a diet program. The second column is the type of candy a guest bought before a diet program, the third column is the type of candy a guest bought after a diet program. I only want to keep the rows which show the unique candy choices before and after the diet program.

 

My data currently looks like this:

 

GuestNo       Before        After        Cost

     1                  A                               3

     1                  A                              3.5  

     1                  A                               3  

     1                  B                               4

     1                  C                               5

     1                                   A            3.75

     1                                   A            3.75

     1                                   B             4.5

     1                                   D              7

     1                                   E              8

     2                  A                             3.25

     2                  F                             9.25

     2                                   F            9.50

     2                                   G             10

 

 

I want to know the amount of money guests spend on unique types of candy before and after the program. Thus, I would like to be able to create a new dataset that looks like this:

 

GuestNo       Before        After        Cost

 

     1                  C                               5

     1                                   D              7

     1                                   E              8

     2                  A                             3.25

     2                                   G             10

 

I have tried using a 'nodupkey' function, but it seems to only delete data from one column at a time, without the ability to read from multiple columns. Any help would be much apprecaited on the topic!

2 REPLIES 2
bnawrocki
Quartz | Level 8

Actually, NODUPKEY works on multiple columns also. If there's more than one record in which ALL the BY vars are the same, it will keep only the first of those records found. So, if you run -

PROC SORT NODUPKEY; 
   BY GUESTNO BEFORE AFTER;

- it should give you close to what you want.

 

I don't entirely understand the output you want, however -- why don't you want to keep row 4 - where CUSTNO=1, BEFORE=B, AFTER=blank? That particcular combination of values is not duplicated anywhere in the file, is it?

 

alooo
Calcite | Level 5

Hi I have encountered similar questions... have you figured it out at last? Thank you!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 2779 views
  • 0 likes
  • 3 in conversation