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

Simple question. How do I filter out values with variables containing: ">" , "<"  ?

example data:

x

as

<as

>as

 

if x (does not contain ">" "<") then y=a;
1 ACCEPTED SOLUTION

Accepted Solutions
jimbarbour
Meteorite | Level 14

Have you tried the Index function?  See example, below.  In the example, the "Want" dataset will only have variables that do NOT contain a "<" or a ">".  If you had other processing to do on other columns, you wouldn't want to do it quite this way.  You'd want to perhaps use a DO - END construct and put the variables affected by a "<" or a ">" inside the DO - END.  The way the example is coded, if the variable "x" has a "<" or a ">" in it, then the entire row will be dropped, which may not be what you want if you only want to skip processing on certain columns but want to still process other columns in the same row.  This is just an example of how to code the INDEX function for a "<" or a ">".  You can customize as suits your needs.

 

Jim

 

DATA	Have;
	INPUT	x	$;
DATALINES;
x
as
<as
>as
;
RUN;
 
DATA	Want;
	SET	Have;
	IF	NOT	((INDEX(STRIP(x), '<'))
		OR	(INDEX(STRIP(x), '>')));
RUN;

View solution in original post

2 REPLIES 2
jimbarbour
Meteorite | Level 14

Have you tried the Index function?  See example, below.  In the example, the "Want" dataset will only have variables that do NOT contain a "<" or a ">".  If you had other processing to do on other columns, you wouldn't want to do it quite this way.  You'd want to perhaps use a DO - END construct and put the variables affected by a "<" or a ">" inside the DO - END.  The way the example is coded, if the variable "x" has a "<" or a ">" in it, then the entire row will be dropped, which may not be what you want if you only want to skip processing on certain columns but want to still process other columns in the same row.  This is just an example of how to code the INDEX function for a "<" or a ">".  You can customize as suits your needs.

 

Jim

 

DATA	Have;
	INPUT	x	$;
DATALINES;
x
as
<as
>as
;
RUN;
 
DATA	Want;
	SET	Have;
	IF	NOT	((INDEX(STRIP(x), '<'))
		OR	(INDEX(STRIP(x), '>')));
RUN;
Ksharp
Super User
DATA	Have;
	INPUT	x	$;
DATALINES;
x
as
<as
>as
;
RUN;
 
DATA	Want;
	SET	Have;
	IF	NOT	findc(x, '<>');
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
  • 2 replies
  • 494 views
  • 1 like
  • 3 in conversation