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;
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;
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;
DATA Have; INPUT x $; DATALINES; x as <as >as ; RUN; DATA Want; SET Have; IF NOT findc(x, '<>'); RUN;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.