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

How to drop cases that does not contain any of the given strings of characters delivered through a local macro?  

data test;                                                
input id $ b c $ d e $ f;                                 
datalines;                                                
AAA 50 11 1 222 22                                        
BBB 35 12 2 250 25                                        
CCC 75 13 3 990 99                                        
;                                                         
run;

proc contents data=test out=vars(keep=name type) noprint; run;

%let rvar = "id", "b";

%let rvar1 = "c", "d", "e", "f";
data vars;
 set vars;
 if name NOT in (&rvar); *Of course this line will not work;                  
 *if name in (&rvar1); 
/*IT works if I set 'rvar' accordingly. 
Though, this can be an option, thre are so many variables
to consider for my data set under this condition; */                
run;
 

 

Exisiting data;

Existing data

Desired data:

Screen Shot 2017-05-29 at 9.05.41 AM.png

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Should be simple.  The meaning of a subsetting if IF statement is that if the condition is NOT met then the data step loop stops. So 

if condition ;

is the same as 

if NOT condition then DELETE;

So in your case you want 

if name NOT in (&rvar) then delete;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Should be simple.  The meaning of a subsetting if IF statement is that if the condition is NOT met then the data step loop stops. So 

if condition ;

is the same as 

if NOT condition then DELETE;

So in your case you want 

if name NOT in (&rvar) then delete;
mamun85
Fluorite | Level 6

Ah! The real problem is being a newbie in SAS. I just could have used:

if name in (&rvar) then delete;  

@Tom Thanks for your edit and answer Tom.

 

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 27208 views
  • 0 likes
  • 2 in conversation