BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ggunaward
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ggunaward
Fluorite | Level 6
Okay thanks everyone I think I see how to do it now. Within my proc iml statement, I need to put my variables into macro variables like in here:

https://stackoverflow.com/questions/25042043/using-a-vector-generated-in-sas-iml-as-a-macro-variable

and then call the macro variable in one of my sgplot labels like in here:

https://blogs.sas.com/content/iml/2021/02/22/byvar-byval-keywords-sas-titles.html

Does that seem like it would work?

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

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.

 

--
Paige Miller
ggunaward
Fluorite | Level 6
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?
PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
ggunaward
Fluorite | Level 6
Okay so essentially for that last part:

/* 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;

I want to replace "xaxis label="Quantiles";"

with "xaxis label="Normal Distribution Kurtosis:" #Kurtosis Variable# "Skewness:" #Skewness Variable#;"
PaigeMiller
Diamond | Level 26

Do you want four separate plots, one for Normal, one for Cauchy, one for Weibull, one for Laplace?

--
Paige Miller
ggunaward
Fluorite | Level 6
No, just one plot. The plot that I have is actually fine. I'm purposely plotting each scatter plot on the same plot. The problem I'm having is that the data is randomly generated from a distribution, and so I want a label that shows in plain text, the kurtosis and skewness for each distribution whenever the sas page is run. Essentially I'm trying to figure out how to put a calculation into a label, either via a variable or by doing the calculation on the dataset right then and there. Is that possible?
jimbarbour
Meteorite | Level 14

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

ggunaward
Fluorite | Level 6
Okay thanks everyone I think I see how to do it now. Within my proc iml statement, I need to put my variables into macro variables like in here:

https://stackoverflow.com/questions/25042043/using-a-vector-generated-in-sas-iml-as-a-macro-variable

and then call the macro variable in one of my sgplot labels like in here:

https://blogs.sas.com/content/iml/2021/02/22/byvar-byval-keywords-sas-titles.html

Does that seem like it would work?
jimbarbour
Meteorite | Level 14
Sounds like it should work.

Jim
ggunaward
Fluorite | Level 6

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 10 replies
  • 1304 views
  • 1 like
  • 3 in conversation