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


Hi All,

          I am working on sgplot barline chart . I am trying to display barline chart with two legends one for the bars and other for line . I want to have the legend values for line chart different from the group xyz .

Below is the code.          

proc sgplot data=xxxx;
vline b/response=a  group=xyz  groupdisplay=cluster y2axis legend=legend1  name="b" ;
vbar b/response=c group=xyz   groupdisplay=cluster name="a" ;
keylegend "a"  "b";
run;

Is there a way where I can change the values of the legend for the vline ?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

I too am trying to understand your use case.  Combining plot statements gets a lot easier if you pre summarize your data (Proc Means), and then use VBARPARM and SERIES plots.  Then, you can use different category and group variables as needed.  With VBAR and VLINE, there are some restrictions.  Which release of SAS are you using?

View solution in original post

7 REPLIES 7
DanH_sas
SAS Super FREQ

To get two legend, you code should look like the following:

proc sgplot data=xxxx;

vline b/response=a  group=xyz  groupdisplay=cluster y2axis name="b" ;

vbar b/response=c group=xyz   groupdisplay=cluster name="a" ;

keylegend "a";

keylegend "b";

run;


What values do you want for the line chart?

sundeep23
Obsidian | Level 7

Hi Dan,

            Thanks for the response.  For line chart I am getting the group variable names of xyz in the legend "b" and I want to  rename those values .

For example :

if the group xyz consists of  ab, bc ,cd

I would get the same naming conventions in both the legends . I cant change the group name in line charts as it a summarized plot.

Thanks.

DanH_sas
SAS Super FREQ

I'm not quite cleat on what you're after. Are you wanting the line chart and bar chart to represent a different set of values from the same group variable?

sundeep23
Obsidian | Level 7

Exactly I want to represent different set of values for the same group variable.

Jay54
Meteorite | Level 14

I too am trying to understand your use case.  Combining plot statements gets a lot easier if you pre summarize your data (Proc Means), and then use VBARPARM and SERIES plots.  Then, you can use different category and group variables as needed.  With VBAR and VLINE, there are some restrictions.  Which release of SAS are you using?

sundeep23
Obsidian | Level 7

Hi Sanjay,

                  Thanks for the info will try with vbarparm . I am using sas 9.4.

Thanks,

Sundeep.

sundeep23
Obsidian | Level 7

Hi Sanjay,

                   Thanks for the help. It worked for me Smiley Happy.

Thanks,

Sundeep.

SAS Innovate 2025: Register Now

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!

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
  • 7 replies
  • 2478 views
  • 1 like
  • 3 in conversation