See if this gives you an idea of one way to select things.
data junk;
input region $ city $ school $;
datalines;
A Milltown Jeffers
B Bigcity Orange
A Milltown Wash
A Treetown Franklin
A Treetown Oddem
B Bigcity Red
A Treetown Betsy
B Bigcity Blue
A Milltown Franklin
B Bigcity Green
B Bigcity Purple
;
run;
%macro dostuff ();
/* determine how many REGIONS and create macro variable to hold them*/
proc sql noprint;
select distinct region into : regions separated by ' '
from junk
;
quit;
/* proc sql creates an automatic variable that has the
number of results for the last query. Save it for use
*/
%let NumRegions = &sqlobs;
%do i=1 %to &NumRegions;
%let region = %scan(®ions,&i);
Proc print data=junk;
Title "Here is where operations involving all of Selected Region would go";
where region="®ion";
run; title;
proc sql noprint;
select distinct city into : cities separated by ' '
from junk
where region ="®ion"
;
quit;
%let NumCities= &sqlobs;
%do j=1 %to &NumCities;
%let city = %scan(&cities,&j);
Proc print data=junk;
Title "Here is where operations involving each city of Selected Region would go";
where region="®ion" and city="&city";
run; title;
Proc sql noprint;
select distinct school into : schools separated by ' '
from junk
where region="®ion" and city="&city"
;
quit;
%let NumSchools=&sqlobs;
%do k = 1 %to &NumSchools;
%let school= %scan(&schools,&k);
Proc print data=junk;
Title "Here is where operations involving each school of Selected Region and City would go";
where region="®ion" and city="&city" and school="&school";
run; title;
%end; /* k loop (schools)*/
%end; /*j loop (city)*/
%end; /*i loop (region)*/
%mend;
%dostuff;
... View more