If you could provide complete details for maybe 4 or 5 of the rules and a dataset (data step please) that would exercise all of the rules and the desired output we might be able to give you more detailed coding support.
Often when I see "one datset per variable" types of solutions often a data re-arrangement can help.
For instance, this code:
select _df2 as _df,count(loan_number) as count from First_Lien_Rules_ETL_&propdate where _df2 = 'df2'
looks like if you had a numeric variable that had values of 0 and 1 with 1 the condition of interest then SUMing it would give the desired count. And you can usually create that type of flag with _df = (a > b) or some other logical.
And then a procedure like Proc Means, Summary, Report or Tabulate can go a long way getting other things. (Mean of a 0/1 variable is percent as decimal in many cases if defined correctly).
Here is a very simple example but the principal may work for your. Note the difference in how OnlyYoungFemale is defined and the effect on the percentage as the conditional assignment changes the denominator.
data junk;
set sashelp.class;
IsFemale = (Sex='F');
IsYoungFemale= (IsFemale and (Age le 14));
If IsFemale then OnlyYoungFemale = (Age le 14);
IsTallYoungFemale = (IsYoungFemale and (Height ge 64));
run;
Proc Tabulate data=junk;
var IsFemale IsYoungFemale OnlyYoungFemale IsTallYoungFemale;
table IsFemale IsYoungFemale IsTallYoungFemale OnlyYoungFemale,
Sum='Count'*f=best4. Mean='%'*f=percent8.1;
label
IsFemale ='Females'
IsYoungFemale ="Young Females of pop"
OnlyYoungFemale= "Young of Females"
IsTallYoungFemale="Young Tall Females of Pop"
;
run;
... View more