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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 870 views
  • 0 likes
  • 3 in conversation