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

Hello,

 

For example; I am trying to keep records which only have the string "street" or "corn" in them, regardless of position/upper/lowercase or anything else - how would I go about doing this?

 

data source;
INFILE DATALINES ;
 input ID VAR & $19. CLASSIFICATION $ ;
 DATALINES;
201  PepsiCo  XYZ  
201  111 main street  XYZ  
201  Charity  XYZ  
331  CocaCola  XYZ  
331  1823 unicorn street  XYZ  
331  Charity  XYZ  
331  Nike  XYZ  
331  123 brock avenue  XYZ  ;
RUN;

For instance: I tried: 

DATA substrings;
	SET source;
IF indexw(var,'street');
RUN;

but it creates an empty data set.

any help is much appreciated, cheers!

1 ACCEPTED SOLUTION

Accepted Solutions
UniversitySas
Quartz | Level 8

Sorry - don't know why it didn't copy properly before - edited it now.

 

Edit: Never mind, got it:

 

 

DATA string;
	SET source;
WHERE varname contains 'street';
RUN;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

post a sample of your data  that's readable and what your required output plz

UniversitySas
Quartz | Level 8

Sorry - don't know why it didn't copy properly before - edited it now.

 

Edit: Never mind, got it:

 

 

DATA string;
	SET source;
WHERE varname contains 'street';
RUN;
ballardw
Super User

@UniversitySas wrote:

Sorry - don't know why it didn't copy properly before - edited it now.

 

Edit: Never mind, got it:

 

 

DATA string;
	SET source;
WHERE varname contains 'street';
RUN;

Does your data set contain a variable named VARNAME? Or are you attempting to use the VARNAME function. If the later then this won't work.

UniversitySas
Quartz | Level 8
That's correct. My input code in the original post should have the column "Varname" instead of "VAR".

Sorry for the mixup!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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