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);

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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