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.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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
  • 6256 views
  • 0 likes
  • 2 in conversation