/***************************************************************************************************************** SAS file name: Save_Statistics.sas File location: _________________________________________________________________________________________________________________ Purpose: Demonstrate how to calculate statistics on SAS procedues and save their values for later use. Author: Peter Clemmensen Creation Date: 01/08/2017 This program supports the blog post "Save Statistics in Macro Variables" on SASnrd.com *****************************************************************************************************************/ /* Mean Refline Example */ /* Compute Setosa mean length and width and save in a dataset */ proc means data=sashelp.iris mean noprint; where Species='Setosa'; var SepalLength SepalWidth; output out=Stats(where=(_STAT_='MEAN')); run; /* Print the output dataset */ proc print data=Stats; run; /* Save relevant statistics in macro variables */ data _null_; set Stats; call symputx('MeanLength', SepalLength); call symputx('MeanWidth', SepalWidth); run; /* Plot scatterplot of Setosa length against width with reflines using calculated statistics */ title 'Sepal Length and Width Scatter Plot'; title2 'With Dynamic Reflines'; proc sgplot data=sashelp.iris; where Species='Setosa'; scatter x=SepalWidth y=SepalLength / markerattrs=(symbol=circlefilled); refline &MeanLength / axis=y lineattrs=(color=red) label="&MeanLength mm" labelattrs=(color=red); refline &MeanWidth / axis=x lineattrs=(color=red) label="&MeanWidth mm" labelattrs=(color=red); run; title;