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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 660 views
  • 2 likes
  • 3 in conversation