Hello Everyone,
I wanted to represent the P-value in the histogram graph. I have used SGPLOT to plot the histogram graph. How can I add the P-value to it.
ods listing close;
options nonumber nodate center;
ods escapechar="^";
ods graphics/ reset imagename = "Overall education" imagefmt = jpeg;
ods listing gpath = "/Projects/Programs";
ods pdf file = "/Projects/Programs/Overall education.pdf";
title "Comparision of Impact on Overall Education between Female and Male";
proc sgplot data=PD2;
histogram femaleedueffect / transparency = 0.6 nbins=5
name="Female" legendlabel="Female" fillattrs=(color=pink);
histogram maleedueffect / transparency=0.6 nbins=5
name="Male" legendlabel="Male" fillattrs=(color=lightblue);
xaxis label="Impact" values = (1 to 5 by 1)
valuesdisplay=("Large -ve impact" "Small -ve impact" "No impact" "Small +ve impact" "Large +ve impact") /*offsetmin= 0.2 offsetmax= 0.2*/;
keylegend "Female" "Male" / across=1 position=TopRight location=Inside;
run;
ods pdf close;
ods listing;
Thanks
You might be thinking of PROC UNIVARIATE, which supports an INSET statement that can automatically add statistics to a histogram.
proc univariate data=sashelp.cars mu0=(20 26);
var mpg_city mpg_highway;
histogram mpg_city mpg_highway;
inset T="t" probt="p-value" / pos=NE format=6.3;
run;
The above example creates two histograms and puts the t statistic and the associated p-value for the Student's t test for the two hypotheses mean(mpg_city)=20 and mean(mpg_highway)=26.
The documentation states that the built-in p-values are for the t-test for location and for a normality test. However, you can put any statistic into a SAS data set and use the DATA= option to add your own labels and p-values from any other test.
If you have the numeric p value, the easiest way to add it on the graph might be in a title2 or footnote statement.
Do you have something specific in mine? A certain location on/around the graph where you'd like to show the numeric p value?
You can also use the INSET statement to put the p-value inside the data area:
inset ("p-value:"="0.05");
The procedure will perform automatic collision avoidance with this inset, or you can explicitly set the position via the POSITION option.
P-value for what hypothesis test?
Any calculation of p-values would have to be done in a PROC before you try to create the plot.
Again I ask: P-value for what hypothesis test? Please be specific, as we need to know this in order to state actual code, rather than general wording of how to do this.
General wording of how to do this
Any PROC allows you to store p-values in output data sets, from there you could create a macro variable that has the value of p-value, and then use the macro variable in the INSET statement.
You might be thinking of PROC UNIVARIATE, which supports an INSET statement that can automatically add statistics to a histogram.
proc univariate data=sashelp.cars mu0=(20 26);
var mpg_city mpg_highway;
histogram mpg_city mpg_highway;
inset T="t" probt="p-value" / pos=NE format=6.3;
run;
The above example creates two histograms and puts the t statistic and the associated p-value for the Student's t test for the two hypotheses mean(mpg_city)=20 and mean(mpg_highway)=26.
The documentation states that the built-in p-values are for the t-test for location and for a normality test. However, you can put any statistic into a SAS data set and use the DATA= option to add your own labels and p-values from any other test.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.