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

Hi All,

I have to keep, if certain grp have both "ABC' and 'DEF' types for that grp i need to keep Type "ALL"

Have data:

grp       type

1          All

1          All

1          All

1          All

1         ABC

1         ABC

1         ABC

1         ABC

2         All

2          All

2          All

2          All

2         ABC

2         ABC

2         ABC

2         ABC

2         DEF

2         DEF

2         DEF

2         DEF

3         All

3         All

2          All

3          All

3         DEF

3         DEF

3         DEF

3         DEF

want:

grp       type

1         ABC

1         ABC

1         ABC

1         ABC

2         All

2          All

2          All

2          All

2         ABC

2         ABC

2         ABC

2         ABC

2         DEF

2         DEF

2         DEF

2         DEF

3         DEF

3         DEF

3         DEF

3         DEF


This is my try:

data want;

do until(last.grp);

set have(keep=group type);

by grp type;

flg=(TYPE eq 'ALL')*1+(TYPE eq 'ABC')*2+(TYPE eq 'DEF')*3;

if flg in(2,3) then keep=1;

output;

end;

run;

Thanks

Sam

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

proc sql;

create table want as

select * from have

group by grp

having count(distinct type)=3 or type ne 'All'

order by grp, type;

quit;

proc print data=want;

run;

View solution in original post

1 REPLY 1
stat_sas
Ammonite | Level 13

proc sql;

create table want as

select * from have

group by grp

having count(distinct type)=3 or type ne 'All'

order by grp, type;

quit;

proc print data=want;

run;

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
  • 1 reply
  • 407 views
  • 0 likes
  • 2 in conversation