Hello experts:
I have a macro program shown below. As you could see every macro is very similar, the difference is in the combination of different numbers. I have about 20 macros (%create_lab) and too long to list here. I am wondering if there is a way to simplify the LONG code. Thanks.
%macro error_check;
%let X=1;
proc sql;
create table lab&X as
select State,ID,age,GEM1,GEM1_CNT
from have
where (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)
order by State,ID;
%macro create_lab;
proc print data=lab&X noobs label;
by State;
title2 "Check &X:&&&lab_&X";
run;
%mend create_lab;
%create_lab;
%let i=(&X + 1 );
%let X=%eval(&i);
proc sql;
create table lab&X as
select State,ID,age,GEM2,GEM2_CNT
from have
where (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)
order by State,ID;
%create_lab;
%let i=(&X + 1 );
%let X=%eval(&i);
proc sql;
create table lab&X as
select State,ID,age,GEM3,GEM3_CNT
from have
where (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)
order by State,ID;
%create_lab;
%let i=(&X + 1 );
%let X=%eval(&i);
proc sql;
create table lab&X as
select State,ID,age,GEM4,GEM4_CNT
from have
where (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)
order by State,ID;
%create_lab;
%let i=(&X + 1 );
%let X=%eval(&i);
.
.
.
%create_lab;
%let i=(&X + 1 );
%let X=%eval(&i);
.
.
.
%create_lab;
%mend error_check;
... View more