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?
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;
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.
You might be able to roll your own plot by writing some custom code in GTL (graphics template language)
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.