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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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