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.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.