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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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