Hello Everyone,
I have two variables. Female effect and Male effect with levels of effect from 1-6 as values. I want to show a graph where it compare these two variable by overlaying along with displaying the 1-6 groups. I was trying it with histogram but was not getting a proper output.
Female Effect | Male Effect |
6 | 4 |
4 | 3 |
3 | 5 |
5 | 2 |
1 | 1 |
4 | |
5 | 5 |
6 | 6 |
3 | 3 |
4 | 2 |
2 | 1 |
3 | 4 |
4 | 5 |
5 | 6 |
6 | 3 |
1 | 5 |
6 | 2 |
5 | 6 |
4 | 1 |
3 | 4 |
4 | 3 |
5 | 2 |
6 | 6 |
3 | |
4 | 2 |
title "Overlay Histograms with PROC SGPLOT";
proc sgplot data=PD;
histogram femaleeffect / transparency=0.3
name="Female" legendlabel="Female" fillattrs=graphdata1;
histogram maleeffect / transparency=0.3
name="Male" legendlabel="Male" fillattrs=graphdata2;
xaxis label="Impact";
keylegend "Female" "Male" / across=1 position=TopRight location=Inside;
run;
I wanted a overlay histogram as sample bellow without density lines:
Thanks!
When I use this code I do not get any density lines using SAS 9.4.4
proc sgplot data=PD; histogram femaleeffect / transparency=0.3 nbins=6 name="Female" legendlabel="Female" fillattrs=(color=pink); histogram maleeffect / transparency=0.3 nbins=6 name="Male" legendlabel="Male" fillattrs=(color=lightblue); xaxis label="Impact" values=(1 to 6 by 1); keylegend "Female" "Male" / across=1 position=TopRight location=Inside; run;
NBINS is the option to control how many columns are displayed. May want to play with Xaxis options to get offsets as desired.
The output shown doesn't match the code+data shown. Verify that you're looking at the correct output for your code, which appears correct.
Note for example the title in the code doesn't match the title in the graphic attached or the legend (iris?)
@RAVI2000 wrote:
Hello Everyone,
I have two variables. Female effect and Male effect with levels of effect from 1-6 as values. I want to show a graph where it compare these two variable by overlaying along with displaying the 1-6 groups. I was trying it with histogram but was not getting a proper output.
Female Effect Male Effect 6 4 4 3 3 5 5 2 1 1 4 5 5 6 6 3 3 4 2 2 1 3 4 4 5 5 6 6 3 1 5 6 2 5 6 4 1 3 4 4 3 5 2 6 6 3 4 2 title "Overlay Histograms with PROC SGPLOT"; proc sgplot data=PD; histogram femaleeffect / transparency=0.3 name="Female" legendlabel="Female" fillattrs=graphdata1; histogram maleeffect / transparency=0.3 name="Male" legendlabel="Male" fillattrs=graphdata2; xaxis label="Impact"; keylegend "Female" "Male" / across=1 position=TopRight location=Inside; run;
I wanted a overlay histogram as sample bellow without density lines:
Thanks!
When I use this code I do not get any density lines using SAS 9.4.4
proc sgplot data=PD; histogram femaleeffect / transparency=0.3 nbins=6 name="Female" legendlabel="Female" fillattrs=(color=pink); histogram maleeffect / transparency=0.3 nbins=6 name="Male" legendlabel="Male" fillattrs=(color=lightblue); xaxis label="Impact" values=(1 to 6 by 1); keylegend "Female" "Male" / across=1 position=TopRight location=Inside; run;
NBINS is the option to control how many columns are displayed. May want to play with Xaxis options to get offsets as desired.
Thank you @Ballarddw. I have tried the above code. By I am not able to get the desired outcome.
Looks like only one color is being represented.
I do have both female and male effect data in the variable.
Check your input data then and post your code and log. I tested your code with the data you posted and it worked perfectly fine.
data PD;
infile cards dlm='09'x truncover;
input femaleeffect maleeffect;
cards;
6 4
4 3
3 5
5 2
1 1
4
5 5
6 6
3 3
4 2
2 1
3 4
4 5
5 6
6 3
1 5
6 2
5 6
4 1
3 4
4 3
5 2
6 6
3
4 2
;;;;
run;
title "Overlay Histograms with PROC SGPLOT";
proc sgplot data=PD;
histogram femaleeffect / transparency=0.3
name="Female" legendlabel="Female" fillattrs=graphdata1 nbins=6;
histogram maleeffect / transparency=0.3
name="Male" legendlabel="Male" fillattrs=graphdata2 nbins=6;
xaxis label="Impact";
keylegend "Female" "Male" / across=1 position=TopRight location=Inside;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.