*Slide 2; *Save a couple macros and a format to show catalogs; proc format; value decadefmt 1948-<1950='1940s' 1950-1959='1950s' 1960-1969='1960s' 1970-1979='1970s' 1980-1989='1980s' 1990-1999='1990s' 2000-HIGH='2000s'; run; /*%macro subset(theschool); proc print; where school="&theschool"; proc means; class school; var rating; where school="&theschool"; run; %mend subset; */ %macro writedata(theschool) data _null_; file "/home/grego1/STAT 541/&theschool..csv" dlm=','; set one; if school="&theschool"; put school rating; run; %mend writedata; *Slide 3; data one; input school$ rating; cards; A 1.5 B 2.3 C 6.5 A 2.5 B 3.3 C 7.5 ; run; *Right click on A.csv to view as text; %INCLUDE "/home/grego1/STAT 541/writedata.txt"; %writedata(A) /* Set up for different use of %INCLUDE from the text example */ proc sql; create table test as select unique school from one; quit; data _null_; file '/home/grego1/STAT 541/macrocalls.txt'; set test; testvar=compress('%writedata(theschool='||school||')'); put testvar; run; *Inspect macrocalls.txt to make sure it was saved correctly; **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'; *Slide 5; *Create catalog macro541 and save subset and macrocalls there--not in Studio; libname macro541 "/home/grego1/STAT 541/macros/"; run; *Slide 7; proc catalog cat=work.sasmac1; contents; quit; proc catalog cat=work.formats; contents; quit; /* Not used at this point in Studio proc catalog cat=macro541.sasmacr; contents; quit; */ *Slide 8; *Be sure to set up macro catalog macro541 and load subset and writedata as source files; * Not in Studio filename catdemo catalog "macro541.macro541.subset.source"; *Use /source2 to show code has been executed; * Not in Studio %include catdemo / source2; * SUBSET macro may not work since WORK.TEST is the current data set; * Find the current data set first by checking LOG after running %PUT; %put &syslast; *If WORK.ONE is not the current data set, reload it prior to running the *SUBSET macro; *%subset(A); /* Not in Studio filename catdemo catalog "macro541.macro541"; %include catdemo(subset) / source2; %include catdemo(writedata) / source2; */ *Slide 12; *An unnecessary command that tells SAS to search for the default AUTOCALL library; options mautosource sasautos=sasautos; options mautosource sasautos=(sasautos,macro541); *Slide 21; *These commands will save subset in the catalog SASMACR in library MACRO541; options mstored sasmstore=macro541; %macro subset(theschool)/store; proc print; where school="&theschool"; proc sort; by school; proc print; by school; where school="&theschool"; proc means; class school; var rating; where school="&theschool"; run; %mend subset; proc catalog cat=macro541.sasmacr; contents; *Store the source code with the compiled macro; options mstored sasmstore=macro541; %macro subset(theschool)/store source; proc print; where school="&theschool"; proc sort; by school; proc print; by school; where school="&theschool"; proc means; class school; var rating; where school="&theschool"; run; %mend subset; proc catalog cat=macro541.sasmacr; contents; quit; *Recreate data set ONE before running this; *Calling a compiled macro; %subset(A) *Accessing source for a compiled macro; %copy subset/source;