BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

Hi. Overlay histogram works but i would like to have certain color appear on top of another. 

 

proc univariate data=work.data;
WHERE var1 between 0 and 100;
class class2;
var var1;
histogram var1 /
endpoints = 0 to 100 by 10
normal overlay
VAXISLABEL = "Percentage of patients" ;
run;

 

Note: class1 = 0 is blue color and class1 = 1 is red color. 

I want the blue to appear on top of red. how do i do that?

1 REPLY 1
RichardDeVen
Barite | Level 11

Sounds like the blue distribution has a higher mean value.

 

Univariate histogram plots will combine the curve colors when an X is in both distributions.  

Do you not want that visual indicator ?

 

For example:

I used generated data with four classes to emphasize what the procedures do:

data have;
call streaminit(123);
do class = 0, 1;
  do _n_ = 1 to 100+100*class;
    x = rand('normal', 45 + 10*class, 4);
    output;
  end;
end;
run;

ods html file='univariate-normal.html';

proc univariate data=have;
  class class;
  var x;
  histogram x / normal overlay;
run;

ods html close;

univariate-normal.pngunivariate-normal.png

 

SGPLOT can also produce histogram plots, and overlay via the GROUP= option. 

Review of produced images indicates the order of the histogram drawing is group mean descending (this is similar to the -mean being a z-index in CSS), so there is no way to force a higher mean distribution plot to be rendered wholly above of a lower mean distribution plot.  The documentation does NOT discuss this situation, and there are no options for changing the group render order. 

sgplot-normal.pngsgplot-normal.png

You might be able to roll your own plot by writing some custom code in GTL (graphics template language)

 

CFC_SAS_Communities_400x225.jpgCFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 1 reply
  • 1474 views
  • 0 likes
  • 2 in conversation