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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.