BookmarkSubscribeRSS Feed
RandyStan
Fluorite | Level 6

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

 

2 REPLIES 2
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Amir
PROC Star

Hi @mkeintz,

 

To avoid confusion, you'll need to insert an underscore in the variable name in:

 

  if vara>'BOT';

 

 

Kind regards,

Amir.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 829 views
  • 0 likes
  • 3 in conversation