*-----------------------------------------------* * QQPLOT: GRAPHS A QUANTILE-QUANTILE PLOT * * * * PARAMETERS NEEDED BY MACRO: * * yvar = variable to plot on vertical axis * * xvar = variable to plot on horizontal axis * * data = name of the input dataset * * (default is _last_) * * gout = name of graphics catalog to output to * * (default is work.gseg) * *----------------------------------------------*; %macro qqplot(yvar=,xvar=,data=_last_,gout=gseg); * Compute n and output to a new dataset, * excluding case if either var is missing.; proc univariate data=&data noprint; where &xvar^=. and &yvar^=.; var &xvar; output out = stats n = n ; * Create a global macro variable of n; data stats; set stats; call symput('n',n); * Sort the data by each plot var and output to separate datasets.; * Keep only the plot vars to save sorting time and disk space.; proc sort data=&data(keep=&xvar &yvar) out=xdat; where &xvar^=. and &yvar^=.; by &xvar; proc sort data=&data(keep=&xvar &yvar) out=ydat; where &xvar^=. and &yvar^=.; by &yvar; * Merge the quantiles one to one and define * two (x,y) points for reference line; data qq; merge xdat(keep=&xvar) ydat(keep=&yvar) ; if _n_ = 1 then x = min(&xvar,&yvar); else if _n_ = &n then x = max(&xvar,&yvar); y=x; axis1 label=(angle=90 height=.75 "&yvar"); axis2 label=("&xvar"); symbol1 interpol=none value=circle color=black height=.5; symbol2 interpol=join value=none color=red; proc gplot data=qq gout=&gout; plot &yvar*&xvar y*x / vminor=1 vaxis=axis1 hminor=1 haxis=axis2 overlay; run; quit; %mend qqplot;