DATA MASTER; FILENAME webpage URL 'http://people.stat.sc.edu/hitchcock/masterschool.txt'; INFILE webpage; INPUT SCHOOL SSN GPA STANINE EXEMPT; run; * Slide 3; PROC SORT DATA=MASTER; BY SCHOOL; PROC PRINT DATA=MASTER; BY SCHOOL; PAGEBY SCHOOL; VAR SSN EXEMPT; TITLE "Student SSNs and Exemption Status"; PROC MEANS DATA=MASTER; BY SCHOOL; VAR GPA; TITLE "Average GPA"; PROC FREQ DATA=MASTER; BY SCHOOL; TABLES STANINE; TITLE "Distribution of Reading Test Stanines"; * Slide 5; %MACRO REPORTS (BEGIN, END); %DO INDEX=&BEGIN %TO &END; OPTIONS PAGENO=1; DATA SCHOOL&INDEX; SET MASTER; IF SCHOOL=&INDEX; PROC PRINT DATA=SCHOOL&INDEX; BY SCHOOL; VAR SSN EXEMPT; TITLE "Student SSNs and Exemption Status"; PROC MEANS DATA=SCHOOL&INDEX; BY SCHOOL; VAR GPA; TITLE "Average GPA"; PROC FREQ DATA=SCHOOL&INDEX; BY SCHOOL; TABLES STANINE; TITLE "Distribution of Reading Test Stanines"; %END; %MEND REPORTS; **THE FOLLOWING STATEMENT GENERATES REPORTS FOR 50 SCHOOLS; %REPORTS(1,50) * Slide 6; %MACRO REPORTS (BEGIN, END); %DO INDEX=&BEGIN %TO &END; OPTIONS PAGENO=1; PROC PRINT DATA=MASTER; BY SCHOOL; VAR SSN EXEMPT; WHERE SCHOOL=&INDEX; TITLE "Student Names and Exemption Status"; PROC MEANS DATA=MASTER; BY SCHOOL; VAR GPA; WHERE SCHOOL=&INDEX; TITLE "Average GPA"; PROC FREQ DATA=MASTER; BY SCHOOL; TABLES STANINE; WHERE SCHOOL=&INDEX; TITLE "Distribution of Reading Test Stanines"; %END; %MEND REPORTS; %REPORTS (1,50) options mprint; data one; input school$ rating; cards; A 1.5 B 2.3 C 6.5 A 2.5 B 3.3 C 7.5 ; %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/davidhitchcock/sasuser.v94/stat541/&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);*/ *Use OUT in PROC FREQ to create variable with each school name; proc freq; tables school/out=test; proc print; run; *Automating the macro calls; data _null_; file '/home/davidhitchcock/sasuser.v94/stat541/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/davidhitchcock/sasuser.v94/stat541/macrocalls.txt'; %include bringin; **the following statement will do the same things as the last two statements; %include '/home/davidhitchcock/sasuser.v94/stat541/macrocalls.txt';