**====================================================================================================; ****************************************************************************** *STEP 1: CREATE 4-LELVEL COMBINATION ******************************************************************************; data comb4; drop i id2 id3 id4 filter_id; set filter nobs=nobs; i+1; do j=i+1 to nobs; set filter (rename=(filter_id=id2 cond1=filter2_name1 value1=filter2_value1 cond2=filter2_name2 value2=filter2_value2)) point=j; do k=j+1 to nobs; set filter (rename=(filter_id=id3 cond1=filter3_name1 value1=filter3_value1 cond2=filter3_name2 value2=filter3_value2)) point=k; do l=k+1 to nobs; set filter (rename=(filter_id=id4 cond1=filter4_name1 value1=filter4_value1 cond2=filter4_name2 value2=filter4_value2)) point=l; filter1st=filter_id; filter2nd=id2; filter3rd=id3; filter4th=id4; output; end; end; end; run; data comb4; set comb4; rename cond1=filter1_name1 value1=filter1_value1 cond2=filter1_name2 value2=filter1_value2; run; ****************************************************************************** *STEP 2: LOOP THROUGH THE ORIGINAL DATA IF match1=2, it means first filter of condition fully meet --> dont need to check filter2 If match2<2, move on to check filter2. IF fully match filter2, Match2=2 ******************************************************************************; data want4; drop i1 j1 i2 j2 found1-found4; set comb4; *array for filter 1; array filter1_name{2} filter1_name1 filter1_name2; array filter1_value{2} filter1_value1 filter1_value2; *array for filter 2; array filter2_name{2} filter2_name1 filter2_name2; array filter2_value{2} filter2_value1 filter2_value2; *array for filter 3; array filter3_name{2} filter3_name1 filter3_name2; array filter3_value{2} filter3_value1 filter3_value2; *array for filter 4; array filter4_name{2} filter4_name1 filter4_name2; array filter4_value{2} filter4_value1 filter4_value2; *Analyze filter 1; DO p1=1 to nobs ; match1=0; set original point=p1 nobs=nobs; array org_var{5} var1 var2 var3 var4 var5; found1=0; do i1=1 to 2 until (found1=1); found2=0; do j1=1 to 5 until (found2=1); if filter1_name{i1}=vname(org_var{j1}) and filter1_value{i1}=org_var{j1} then do;match1=match1+1;found2=1;end; *Once find the match, dont need to check further within the original record but move to the next condition in the same filter (i1=2); end; if match1=2 then do; found1=1;match2=.;match3=.;output;end; *If the first condition in the filter fully satisfy, the whole filter is done-->move to the next filter_id; end; *if filter 1 fail, go to filter2; IF match1<2 then do; found3=0; match2=0; do i2=1 to 2; found4=0; do j2=1 to 5 until (found4=1); if filter2_name{i2}=vname(org_var{j2}) and filter2_value{i2}=org_var{j2} then do; match2=match2+1;found4=1;end; *Once find the match, dont need to check further within the original record but move to the next condition in the same filter (i1=2); end; if match2=2 then do; found1=1;match3=.;output;end; *If the second condition in the filter fully satisfy, the whole filter is done-->move to the next filter_id; end; end; *if filter 2 fail, go to filter3; IF match1<2 and match2<2 then do;/*because I close the checking of each filter right away, each checking is independent, that's why in need match1 match2<2*/ found5=0; match3=0; do i3=1 to 2; found6=0; do j3=1 to 5 until (found6=1); if filter3_name{i3}=vname(org_var{j3}) and filter3_value{i3}=org_var{j3} then do; match3=match3+1;found6=1;end; *Once find the match, dont need to check further within the original record but move to the next condition in the same filter (i1=2); end; if match3=2 then do; found1=1;match4=.;output;end; *If the second condition in the filter fully satisfy, the whole filter is done-->move to the next filter_id; end; end; *if filter 3 fail, go to filter4; IF match1<2 and match2<2 and match3<2 then do;/*because I close the checking of each filter right away, each checking is independent, that's why in need match1 match2 match3<2*/ found7=0; match4=0; do i4=1 to 2; found8=0; do j4=1 to 5 until (found8=1); if filter4_name{i4}=vname(org_var{j4}) and filter4_value{i4}=org_var{j4} then do; match4=match4+1;found8=1;end; end; end; /*if match4=2 then do; found1=1; output; end;/*this only output those with match =2;*/ output;*this output everything, create a file of m*n; end; end; run; proc sort data=want4; by filter1st filter2nd id;run;
... View more