BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RAVI2000
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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.

View solution in original post

8 REPLIES 8
GraphGuy
Meteorite | Level 14

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?

 

RAVI2000
Lapis Lazuli | Level 10
I want to show it in the top right corner of the graph.
DanH_sas
SAS Super FREQ

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.

 

 

RAVI2000
Lapis Lazuli | Level 10
How is the INSET statement going to calculate the P-value?
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
RAVI2000
Lapis Lazuli | Level 10
Yes, you are right. But how do I use that P- value in my SGPLOT again?

If i am using proc univariate I can only perform for one histogram. I also want to overlay the graph with different group. And how am I supposed to get p-value for both the variables that I am looking for.

Can you provide the proc code with p-value calculation for two or more variable?
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Rick_SAS
SAS Super FREQ

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1928 views
  • 2 likes
  • 5 in conversation