Why do you specify that Proc SQL has to be used?
I suspect that Proc Summary will generate the needed result in one pass. Select the appropriate _TYPE_ value if you need them split out.
Consider this example. You should have the SAS supplied data set SASHELP.CARS in your installation so the code would run and generate output.
Proc summary data=sashelp.cars;
class origin make type;
var msrp;
output out=work.summary sum=;
run;
When you examine the output data set, WORK.SUMMARY, the summary will have the sum of the variable MSRP by overall, each level of the variables Origin, Make and Type alone and in combinations of 2 or 3 at a time the. Variable _TYPE_ can be used to subset the result as needed.
IF you only need specific values of any of the Class variables you can use a WHERE clause to restrict them but the way you asked your question is not clear whether the "lists" are specified or if you want all the values that may change.
An additional advantage of Proc Summary over Proc SQL is if you need other variables summarized you just add the variable to the VAR statement. Also if additional statistics are needed, such as Min and Max, you can add the option /autoname to the output line and SAS will create variable names with the statistic appended. With Proc SQL you would have to write some possibly very complex code to create variable names.
Example requesting different statistics for different variables
Proc summary data=sashelp.cars;
class origin make type;
var msrp invoice horsepower weight ;
output out=work.summary2
sum(msrp invoice) = min(horsepower weight)= max(horsepower weight)=
mean(horsepower weight)= /autoname
;
run;
... View more