BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a dataset with the variable "field_number" and I want to retain all records that start with a 'T' or 'B'. I am using this macro substitution and calling it in a where clause:

%let fieldnum = 'T%' or 'B%';

data step1; set data;
where Field_number like &fieldnum
run;

It works if I only want 'T%' samples but not if I also want 'B%' samples. Seems simple, but I just can't figure out the correct syntax.
8 REPLIES 8
data_null__
Jade | Level 19
Don't you need another like operator?

%let fieldnum = like 'T%' or like 'B%';
data_null__
Jade | Level 19
Don't you need another like operator?

%let fieldnum = like 'T%' or like 'B%';
deleted_user
Not applicable
I suppose that would work but it's not the clean solution I was looking for. Tried it and received errors. Probably have incorrect parenthesis in the where clause.


Message was edited by: DDC
deleted_user
Not applicable
Why not just:

where field_number in: ('T' 'B');
deleted_user
Not applicable
Because the field_number is more than one character, and I want those that start with T or B (which is why I have the %). And I can't get IN to work with character wildcard.
deleted_user
Not applicable
The colon after the IN tells SAS to look for cases where the value starts with the characters/s in the quotes.
deleted_user
Not applicable
Ahhh, I overlooked the colon in your post. Works now. Good to know. Thanks a lot.
deleted_user
Not applicable
Yeh, it's only little but it can save a whole lot of effort.

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
  • 8 replies
  • 4328 views
  • 0 likes
  • 2 in conversation