/* Macros */ %macro ecns; /* Specify the final iteration number */ %let nobsend = 15; /* Specify the end point of each iteration */ %do i=5 %to &nobsend %by 5; /* Data set name to reflect # of observations */ data sim&i; /* Create i number of observations */ do j=1 to &i ; y = rand("Normal",0,1); output; end; run; %end; %mend; /* Run the created macro */ %ecns; /* Iterate over a SAS procedure */ %macro correlate; /* Specify excel file name */ %let sasRes = corrresults.xls ; /* Specify that your results are written into an Excel file */ ods tagsets.excelxp file = "&sasRes" /* Specify filename */ style = printer /* Specify display style (default, minimal, printer) */ options( /* Specify other options */ orientation = "landscape" /* Tables displayed in landscape */ pages_fitwidth = "1" /* Fits tables to defined page width */ pages_fitheight = "100" /* Fits tables to defined # of pages */ sheet_interval = "proc" /* Places tables in specified sheets (none,proc,table) e.g., "none" will put all output tables into one sheet "proc" places tables from each procedure in individual sheets */ ); /* Iterate over three variable names */ %do i=1 %to 3; %if &i=1 %then %let var = invoice; %if &i=2 %then %let var = cylinders; %if &i=3 %then %let var = horsepower; /* Run the dynamic correlation procedure; calls a different variable in each iteration */ proc corr data=sashelp.cars; var msrp &var; run; %end; /* End writing to the excel file */ ods tagsets.excelxp close; %mend; %correlate;