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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 788 views
  • 1 like
  • 3 in conversation