BookmarkSubscribeRSS Feed
kz134
Obsidian | Level 7

Hi, 

 

I have a large dataset with many different column names. I want to have an if statement that filters for all columns. 

 

For example, I have a table:

 

row_numberName1Name2Name3Name4Name5
13491XXX
27XXX295
322286
4721XXX3
5109352

 

I want the output to be rows with the value XXX in it. 

 

row_numberName1Name2Name3Name4Name5
13491XXX
27XXX295
4721XXX3

 

My table name is not uniform like that (not like 1,2,3,4...). They are just english words. 

 

Thank you. 

 

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Can i assume the vars name1--name6 are all char vars?

 

if yes,

 

data have;
input row_number	(Name1	Name2	Name3	Name4	Name5) ($);
cards;
1	3	4	9	1	XXX
2	7	XXX	2	9	5
3	2	2	2	8	6
4	7	2	1	XXX	3
5	10	9	3	5	2
;

data want;
set have;
array t name1--name5;
if 'XXX' in t;
run;

the double -- takes care of the variable list even it is not sequential list 1-6 meaning any variable name from left to right

novinosrin
Tourmaline | Level 20

or it the vars are mix of char and num, grouping the array var on all chars and filtering it should work fine too like

data want;
set have;
array t _character_;
if 'XXX' in t;
run;
Reeza
Super User

WHICHC()

 

if whichc('XXX', of name1--name5);

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 3 replies
  • 914 views
  • 2 likes
  • 3 in conversation