I want to output a variable with a value greater than BOT
Var_A
120
130
BOT
123
BOT 67 2
BOT 5 7
BOT
MAN
I want to extract those values of the variable greater than BOT
So the output I need is
BOT 67 2
BOT 5 7
Thanks in advance
You say that you "want to extract those values of the variable greater than BOT". But as far as I can tell you merely want the lines of data in which the value of the variable VARA is the word "BOT" followed by some non-blank value. In lexicographic ordering I guess that does qualify as "greater than". If so, then:
data have;
input var_a $10.;
datalines;
120
130
BOT
123
BOT 67 2
BOT 5 7
BOT
MAN
run;
data want;
set have;
where var_a =: 'BOT';
if var_a>'BOT';
run;
The '=:' relation in the where statement tells sas to read in only those records with VAR_A starting with 'BOT'. The subsetting IF then keep only the subset that has something other than a blank following the 'BOT'.
Edit note: Forgot to change if vara>'BOT' to if var_a>'BOT'. Thanks @Amir for the note.
Hi @mkeintz,
To avoid confusion, you'll need to insert an underscore in the variable name in:
if vara>'BOT';
Kind regards,
Amir.
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!
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.