data test02(drop = t);
set test01;
if b > a then output;
t = a;
a = b;
b = t;
if b > a then output;
run;
proc sort data = test02;
by a b;
run;
data test03;
set test01(keep = a rename=(a = ab))
test01(keep = b rename=(b = ab));
run;
proc sort data = test03 nodupkey;
by ab;
run;
%macro test_macro();
%let grp = 0;
%do flag1 = 1 %to 0 %by -1;
%let grp = %eval(&grp.+1);
%do flag2 = 1 %to 0 %by -1;
%let ds_flag = %sysfunc(open(temp01,is));
%if &ds_flag. = 0 %then %do;
data _null_;
if _n_ = 1 then do;
dcl hash h();
h.definekey("ab");
h.definedata("ab");
h.definedone();
end;
set test02 end=eof;
if _n_ = 1 then do;
ab = a; h.add();
ab = b; h.add();
end;else do;
if h.find(key:a) = 0 and h.find(key:b) then do;
ab = b; h.add();
end;else if h.find(key:a) and h.find(key:b) = 0 then do;
ab = a; h.add();
end;
end;
if eof then h.output(dataset:"temp01");
run;
%end;
%else %do;
%let ds_close = %sysfunc(close(&ds_flag.));
data _null_;
if 0 then set temp01;
if _n_ = 1 then do;
dcl hash h(dataset:"temp01");
h.definekey("ab");
h.definedone();
end;
set test02 end=eof;
if h.find(key:a) = 0 and h.find(key:b) then do;
ab = b; h.add();
end;else if h.find(key:a) and h.find(key:b) = 0 then do;
ab = a; h.add();
end;
if eof then h.output(dataset:"temp02");
run;
proc sql noprint;
select count(*) into:t1 from temp01;
select count(*) into:t2 from temp02;
quit;
data temp01; set temp02; run;
%if &t1. = &t2. %then %let flag2 = -10;
%else %let flag2 = 1;
%end;
%end;
data temp01; set temp01; grp = &grp.; run;
proc append base = temp03 data = temp01; run;
data test02;
if 0 then set temp03;
if _n_ = 1 then do;
dcl hash h(dataset:"temp03");
h.definekey("ab");
h.definedone();
end;
set test02;
if h.find(key:a) and h.find(key:b);
run;
proc sql noprint;
select count(*) into:tp3 from temp03;
select count(*) into:tt3 from test03;
drop table temp01;
drop table temp02;
quit;
%if &tp3. = &tt3. %then %let flag1 = -10;
%else %let flag1 = 1;
%end;
%mend;
%test_macro();