There is rarely a need to split data sets like this. I know this is an assignment you have to work on, but some day you are going to be in the real world and there will be a problem just like this, and what I am saying (and I think @Kurt_Bremser is saying) is that you shouldn't split the data set. Why? Because (except for rare cases) the BY statement does exactly what this macro splitting the data sets does and then some; also the BY statement works in most PROCs, so you can perform the task separately for each category (in your data set, the category was REGION) without splitting the data set.
Here's an example of not splitting the data set and making use of the BY statement.
proc sort data=sashelp.cars out=cars;
by origin;
run;
proc freq data=cars;
by origin;
table type drivetrain make;
run;
proc means data=cars;
by origin;
var msrp invoice horsepower weight wheelbase length;
run;
Here's the same analysis, if you have to split the data and you don't use the BY statement. Please examine the code above and the code below and determine which code is shorter and easier.
%macro split;
proc sql noprint;
select distinct origin
into :origlist1-
from sashelp.cars;
quit;
data %do i=1 %to &sqlobs; gm&i %end; ;
set sashelp.cars;
%do i=1 %to &sqlobs; if origin="&&origlist&i" then output gm&i%str(;) %end;
run;
%mend;
%split
proc freq data=gm1;
table type drivetrain make;
run;
proc freq data=gm2;
table type drivetrain make;
run;
proc freq data=gm3;
table type drivetrain make;
run;
proc means data=gm1;
var msrp invoice horsepower weight wheelbase length;
run;
proc means data=gm2;
var msrp invoice horsepower weight wheelbase length;
run;
proc means data=gm3;
var msrp invoice horsepower weight wheelbase length;
run;
Unfortunately, the person who designed your assignment created an assignment that teaches the wrong lesson. After you finish the assignment, and you go out into the real world and you want to analyze data split by some category, a person who completed this assignment knows: "I can write a macro and split the data set". That is the wrong lesson. The right lesson to learn is that you can do this without splitting the data set (except for rare cases) by using the BY statement to split and analyze the data.
... View more