*---------------------------------------------------* * SYMMPLOT: GRAPHS A SYMMETRY PLOT USING PROC GPLOT * * * * PARAMETERS NEEDED BY MACRO: * * data = name of the input dataset * * (default is _last_) * * var = name of the variable you want to plot * * gout = name of graphics catalog to output to * * (default is work.gseg) * *---------------------------------------------------*; %macro symmplot(data=_last_,var=,gout=gseg); * Create dataset with median and n; proc univariate data=&data noprint; var &var; output out = stats median = med n = n ; * Create even/odd flag for n and convert * n, flag and median to global vars; data stats; set stats; nmod2 = mod(n,2); call symput('nmod2',nmod2); call symput('med',med); call symput('n',n); * Sort the dataset by the plot variable; proc sort data=&data out=sorted(keep=&var); by &var; * Compute distances above and below median and output to * separate datasets depending on whether above or below; * Note: the computation is different for even and odd n; data above(drop=b) below(drop=a); set sorted; i = _n_; * n is even; if &nmod2 = 0 then do; if i <= &n/2 then do; b = &med - &var; output below; end; else do; a = &var - &med; output above; end; end; * n is odd; else do; if i <= (&n + 1)/2 then do; b = &med - &var; output below; end; if i >= (&n + 1)/2 then do; a = &var - &med; output above; end; end; * Merge above and below datasets and define * two (x,y) points for a reference line.; proc sort data=above; by descending i; data ab; merge above below; * n is even; if &nmod2 = 0 then do; if i = 1 then x = min(a,b); else if i = &n/2 then x = max(a,b); y=x; end; * n is odd; else do; if i = 1 then x = min(a,b); else if i = (&n+1)/2 then x = max(a,b); y=x; end; * Graph the symmetry plot with the reference line overlayed.; axis1 label=(angle=90 height=.75 "Distance above median of &var"); axis2 label=("Distance below median of &var"); symbol1 interpol=none value=circle color=black height=.5; symbol2 interpol=join value=none color=red; proc gplot gout=&gout; plot a*b y*x / vaxis=axis1 vminor=0 haxis=axis2 hminor=0 noframe overlay; run; quit; %mend symmplot;