A large part of your problem with this thread is you haven't asked a clear question, or clear answers to other folks' questions.
In any case, assuming I've properly guessed what you're trying to do, this is how I'd approach it:
data metadata;
length id 8 where $1000;
infile datalines;
input;
id+1;
where=_infile_;
datalines4;
(State in (1,2,8) and GEM1 not in (0,2)) or (State in (3,5,6) and GEM1 not in (0,8)) or (State in (1,2,8) and GEM1=1 and GEM1_CNT is null)
(State in (3,4,6,8) and GEM2 not in (0,1,2)) or (State in (1,2,5) and GEM2 not in (8)) or (State in (4,8) and GEM2=1 and GEM2_CNT is null)
(State in (3,4,6) and GEM3 not in (8)) or (State in (2,5,8) and GEM3 not in (0,1,2)) or (State in (1,2,5) and GEM3=1 and GEM3_CNT is null)
(State in (3,4,9) and GEM4 not in (6,8)) or (State in (0,5,9) and GEM4 not in (6,9)) or (State in (6,8) and GEM4=1 and GEM4_CNT is null)
;;;;
run;
%macro code;
%let id=%trim(id);
%let where=%trim(&where);
proc sql;
create table lab&id as
select State,ID,age,GEM1,GEM1_CNT
from have
where &where
order by State,ID;
quit;
proc print data=lab&id noobs label;
by State;
title2 "Check &id:lab&id";
run;
%mend;
%loop_control(control=metadata)
Download these macros:
https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas
https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas
... View more