Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching multiple variables (newbie) 1

Status
Not open for further replies.

Asender

Programmer
Jun 4, 2003
31
GB
Hi there.

Can anyone come up with a bit of code which would achive the following:

I have a dataset which contains 44 variables.

MRPOLICY KEY COMCOM1 COMCOM2.......COMCOM42

I need to search through all the COMCOM variables (1 to 42) for a certain string say 'SINGLE';

I can code the longway for this by doing 42 where/or statements like.

WHERE COMCOM1 ? 'STRING' or
WHERE COMCOM2 ? 'STRING' or...

There must be an easier way.

I have been toying with macro variables and do loops but my efforts have amounted to zilch.

Here is some of my effort so far. This obviously does not work.

data test3;
set AS.TEST2;
%let i = 1;
do;
%let i = (&i+1);
where comcom&i ? 'SINGLE';
if &i = 42 then goto out;
end;
out:;
run;

Can anyone help?

Cheers,


Chris....
 
Here:

data test3;
set AS.TEST2;

%macro search;
where comcom1 contains 'SINGLE'
%do i = 1 %to 42;
or comcom&i contains 'SINGLE'
%end;
%mend search;

%search;

run;
 
It should be this:

data test3;
set AS.TEST2;

%macro search;
where comcom1 contains 'SINGLE'
%do i = 2 %to 42;
or comcom&i contains 'SINGLE'
%end;
%mend search;

%search;

run;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top