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

Hi SAS Friends, 

Would appreciate some advice on using PROC SQL to filter out a list of excluded terms from a large dataset, am using SAS 9.4

In the example below, the data set COLORS contains the terms to exclude, under the variable "color".

The data set Storys contains the variable "Fruit_Storys".  If a term from "color" is found in "Fruit_Storys", need to exclude that row.

So in this example, the only rows that would remain after filtering : 

5 sour grey raisins are never chosen
6 sour orange raisins are sometimes chosen

 

Example is :

data COLORS; 
input color $20. ; 
datalines;
red delicious
purple parsimmons 
green and
blue gala
;

data Storys ;
input ID $2. Fruit_Storys $64.;
datalines ;
1 red delicious apples are the prode of NY 
2 the sweet purple parsimmons are too ripe 
3 yellow and blue gala apples are superb 
4 granny apples are green and lean 
5 sour grey raisins are never chosen 
6 sour orange raisins are sometimes chosen 
;

I know this is straight forward for many of you, and hope to have that level of fluency, some day,

greatly appreciate your guidance, 

Thank you !

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data COLORS; 
input color $20. ; 
datalines;
red delicious
purple parsimmons 
green and
blue gala
;

data Storys ;
input ID $2. Fruit_Storys $64.;
datalines ;
1 red delicious apples are the prode of NY 
2 the sweet purple parsimmons are too ripe 
3 yellow and blue gala apples are superb 
4 granny apples are green and lean 
5 sour grey raisins are never chosen 
6 sour orange raisins are sometimes chosen 
;

proc sql;
 create table want as
 select distinct id, Fruit_Storys
 from storys, colors
 group by id
 having not max(find(Fruit_Storys,strip(color)));
quit;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
data COLORS; 
input color $20. ; 
datalines;
red delicious
purple parsimmons 
green and
blue gala
;

data Storys ;
input ID $2. Fruit_Storys $64.;
datalines ;
1 red delicious apples are the prode of NY 
2 the sweet purple parsimmons are too ripe 
3 yellow and blue gala apples are superb 
4 granny apples are green and lean 
5 sour grey raisins are never chosen 
6 sour orange raisins are sometimes chosen 
;

proc sql;
 create table want as
 select distinct id, Fruit_Storys
 from storys, colors
 group by id
 having not max(find(Fruit_Storys,strip(color)));
quit;
PGStats
Opal | Level 21
proc sql;
select *
from storys as a
where not exists (select * from colors where a.fruit_storys contains trim(color));
quit;
PG
rmacarthur
Pyrite | Level 9

Thanks, both relies worked, and chose the former mainly bc it was easier to incorporate into my code , much appreciated !

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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