Hi so I'm trying to set up dynamic x axis labels for an sgplot plot, but can't figure out how to do it. I did the calculations in proc iml and stored them:
/* Calculate skewness and kurtosis for each sample */
proc iml;
use CombinedSamples;
read all;
kurtosis_Normal = kurtosis(Normal);
kurtosis_Cauchy = kurtosis(Cauchy);
kurtosis_Weibull = kurtosis(Weibull);
kurtosis_Laplace = kurtosis(Laplace);
skewness_Normal = skewness(Normal);
skewness_Cauchy = skewness(Cauchy);
skewness_Weibull = skewness(Weibull);
skewness_Laplace = skewness(Laplace);
print "Results";
print kurtosis_Normal kurtosis_Cauchy kurtosis_Weibull kurtosis_Laplace;
print skewness_Normal skewness_Cauchy skewness_Weibull skewness_Laplace;
store _all_ module=_all_;
quit;
Not sure how to add it to the axis of my graph:
/* Set Up for Part C */
proc rank data=CombinedSamples normal=blom out=CombinedSamplesQuant;
var Normal Cauchy Weibull Laplace;
ranks Normal_Quant Cauchy_Quant Weibull_Quant Laplace_Quant;
run;
/* Create Combined QQPlots */
title 'Q-Q Plot for Normal, Cauchy, Weibull, and Laplace Distributions';
proc sgplot data=CombinedSamplesQuant;
scatter x=Normal_Quant y=Normal;
scatter x=Cauchy_Quant y=Cauchy;
scatter x=Weibull_Quant y=Weibull;
scatter x=Laplace_Quant y=Laplace;
xaxis label="Quantiles";
yaxis min=-500 max=500;
run;
Do I need to instead do the calculations in a macro or somehow within sgplot?
If you want to overlay scatter plots into one big PROC SGPLOT output, you can have a legend created that indicates which color scatterplot belongs to which data. For example, see here: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n1vkttjoy99wkwn1iyy9leor7xg2.htm but in this case, the values of the x-axis variable are the same in each call to SERIES (same would be true for SCATTER). Your code doesn't show that, but I think you can rearrange your data such that the x-axis is a variable named QUANTILE for each plot.
Do I need to instead do the calculations in a macro or somehow within sgplot?
No.
@ggunaward wrote:
I think you're misunderstanding. I'm not trying to change the plot at all. I'm trying to take the calculations from my proc iml statement, for example kurtosis_Normal and kurtosis_Cauchy, and replace "Quantiles" in xaxix label with them. Is that possible?
Can you show us (even if it is a hand-drawing) what you want?
Do you want four separate plots, one for Normal, one for Cauchy, one for Weibull, one for Laplace?
I'm not sure it this is completely applicable, but Rick Wicklin wrote a post a few months ago (February 2021) on customizations. He talks about different means of doing this including simple things like #ByVar and #ByVal (which I don't think will help us here) but also more complex things using SGPANEL and Macros for customizing things. I'm not sure if it will be helpful, but I thought it worth mentioning:
https://blogs.sas.com/content/iml/2021/02/22/byvar-byval-keywords-sas-titles.html
Jim
It worked! Thanks! Also had to reference this for the right quotations for the strings:
https://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001071889.htm
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.