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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 465 views
  • 0 likes
  • 3 in conversation