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

Hi,

I have upload my question. And I know how to sketch the normal distribution but just have no idea how to color the confident interval.

My code is

 

data Q4;
do mean=0;
do x=-5 to 5 by .01;
y=pdf('normal',x,mean,1);
output;
end;
end;
run;

proc sgplot data=Q4;
band x=x lower=0 upper=y / group=mean transparency=.5;
series x=x y=y / group=mean;
run;

 

I think I need to modify the "band" there but don't know how. Anyone could help me with that??

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data normalpdf;
    lower_q = quantile('normal', .05/2);
    upper_q = quantile('normal', (1 - .05/2));

   do x=-4 to 4 by 0.01;
      y=pdf('normal',x);
      output;
   end;
    x = .; y = .;

   do lower_x_band = -4 to lower_q by 0.01;
      lower_band = pdf('normal',lower_x_band);
      output;
   end;
   lower_x_band = .; lower_band = .;
 
   do upper_x_band = upper_q to 4 by 0.01;
      upper_band = pdf('normal',upper_x_band);
      output;
   end;
   upper_x_band = .; upper_band = .;
run;

proc sgplot data=normalpdf noautolegend;
   series x=x y=y;
   band x = lower_x_band upper = lower_band lower = 0;
   band x = upper_x_band upper = upper_band lower = 0;
   yaxis offsetmin=0 min=0;
   xaxis label = 'x' min=-4.5 max=4.5;
run;
title;

Result:

 

 

 

Udklip.PNG

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data normalpdf;
    lower_q = quantile('normal', .05/2);
    upper_q = quantile('normal', (1 - .05/2));

   do x=-4 to 4 by 0.01;
      y=pdf('normal',x);
      output;
   end;
    x = .; y = .;

   do lower_x_band = -4 to lower_q by 0.01;
      lower_band = pdf('normal',lower_x_band);
      output;
   end;
   lower_x_band = .; lower_band = .;
 
   do upper_x_band = upper_q to 4 by 0.01;
      upper_band = pdf('normal',upper_x_band);
      output;
   end;
   upper_x_band = .; upper_band = .;
run;

proc sgplot data=normalpdf noautolegend;
   series x=x y=y;
   band x = lower_x_band upper = lower_band lower = 0;
   band x = upper_x_band upper = upper_band lower = 0;
   yaxis offsetmin=0 min=0;
   xaxis label = 'x' min=-4.5 max=4.5;
run;
title;

Result:

 

 

 

Udklip.PNG

YangYY
Quartz | Level 8
Thank you so much!!
Have a nice day!!
PeterClemmensen
Tourmaline | Level 20

Anytime. You can read about the technique in the blog post How to overlay custom curves with PROC SGPLOT .

 

Have a nice day

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 1030 views
  • 4 likes
  • 2 in conversation