BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

 Hello:


I have the sample dataset list below.  I would like to remove the duplicates of "Group" of (100, 200, 300 and 400) if I could find the
same text in the subgroup of 101-199, 201-299, 301-399 or 401-499.   Please help.   Thanks.

 

data test;
      infile datalines dsd;
  input Group Class : $20. Component : $20. Product : $20.;
datalines;
100, ANTI/INSULIN,  ,  ,
100, ANTI/VITA,  ,  ,
100, PHENAZO,  ,  ,
112, ANTI/VITA,  ,  ,
150, PHENAZO,  ,  ,
180, PHENAZO,  ,  ,
181, Large,  ,  ,
200,  ,  HERBS,  ,
200,  ,  PSYCH,   ,
200,  ,  BANZOCAINE,   ,
200,  ,  Large,   ,
210,  ,  SKIN,   ,
270,  ,  HERBS,   ,
280,  ,  BANZOCAINE,   ,
300,  ANTI/INSULIN,   ,  PHENAZO,
300,  ANTI/INSULIN,   ,  ANTI/VITA,
322,  ANTI/INSULIN,   ,  PHENAZO,
377,  ANTI/INSULIN,   ,  Large,
400,  ,   ,  FLOWER,
400,  ,   ,  SUBST,
421,  ,   ,  BANZOCAINE,

422,  ,   ,  FLOWER,
;

 

data final;
      infile datalines dsd;
  input Group Class : $20. Component : $20. Product : $20.;
datalines;
100, ANTI/INSULIN,  ,  ,
112, ANTI/VITA,  ,  ,
150, PHENAZO,  ,  ,
180, PHENAZO,  ,  ,
181, Large,  ,  ,
200,  ,  PSYCH,   ,
200,  ,  Large,   ,
210,  ,  SKIN,   ,
270,  ,  HERBS,   ,
280,  ,  BANZOCAINE,   ,
300,  ANTI/INSULIN,   ,  ANTI/VITA,
322,  ANTI/INSULIN,   ,  PHENAZO,
377,  ANTI/INSULIN,   ,  Large,
400,  ,   ,  SUBST,
421,  ,   ,  BANZOCAINE,

422,  ,   ,  FLOWER,
;

3 REPLIES 3
Reeza
Super User
Please use the code editor to include your code in posts. Otherwise it gets garbled or adds in invisible characters when you try and paste it into SAS Studio.
Shmuel
Garnet | Level 18

data test;
      infile datalines dsd;
  input  Group_code 1.  @-1  Group 3.  Class : $20. Component : $20. Product : $20.;
datalines;

--- your data ---

; run;

proc sort data=test; by group_code class Component Product ; run;

 

data want;

   set test;

         by group_code class Component Product ;

              if first.Product and last.Product;    /* remove duplicates */

run;

Shmuel
Garnet | Level 18

Alternativly to line: 

 input  Group_code 1.  @-1  Group 3.  Class : $20. Component : $20. Product : $20.;

use:

 input   Group  Class : $20. Component : $20. Product : $20.;

group_code = int(group/100);

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