options mprint; data one; input school$ rating; datalines; A 1.5 B 2.3 C 6.5 A 2.5 B 3.3 C 7.5 ; run; %macro subset(theschool); proc print; where school="&theschool"; proc means; class school; var rating; where school="&theschool"; run; %mend subset; *Naive approach to creating separate subsets; /*%subset(theschool=A);*/ /*%subset(theschool=B);*/ /*%subset(theschool=C);*/ %macro writedata(theschool); data _null_; file "/home/grego1/STAT 541/&theschool..csv" dlm=','; set one; if school="&theschool"; put school rating; run; %mend writedata; *Naive approach to writing separate comma-delimited files of subsets; /*%writedata(theschool=A);*/ /*%writedata(theschool=B);*/ /*%writedata(theschool=C);*/ *Create a data set of unique school names; proc sql; create table test as select unique school from one; quit; *Automating the macro calls; data _null_; file '/home/grego1/STAT 541/macrocalls.txt'; set test; testvar=compress('%writedata(theschool='||school||');'); put testvar; run; **the following two statements will execute the macro references in macrocalls.txt; **when you execute this program, it will also execute the statements in the external file; filename bringin '/home/grego1/STAT 541/macrocalls.txt'; %include bringin; **the following statement will do the same things as the last two statements; %include '/home/grego1/STAT 541/macrocalls.txt';