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 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:

RAVI2000_0-1643066144740.png

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

7 REPLIES 7
Reeza
Super User

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:

RAVI2000_0-1643066144740.png

 

Thanks!





RAVI2000
Lapis Lazuli | Level 10
Hello @Reeza,

That graph is just a sample one. It's not the graph from code.
ballardw
Super User

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.

RAVI2000
Lapis Lazuli | Level 10

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.

RAVI2000_0-1643071121615.png

I do have both female and male effect data in the variable.

 

Reeza
Super User

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;
RAVI2000
Lapis Lazuli | Level 10
Thank you @Reeza! There was a small error in my code. I found it and it is working now.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1103 views
  • 3 likes
  • 3 in conversation