BookmarkSubscribeRSS Feed
Fred_Gavin
Calcite | Level 5
Dear all,

sgplot automatically shows up the legend in the output of the graph.

Say in my plot, there are 3 lines, total, female, male.

What if in the legend, I only want the legend for female and male, but suppress the legend for total?

Thanks and Regards

Fred
12 REPLIES 12
deleted_user
Not applicable
Try this:

proc sgplot data=sashelp.stocks
(where=(date >= "01jan2000"d and stock = "IBM"));
title "Stock Trend";

series x=date y=close / name="A";
series x=date y=low / name="B";
series x=date y=high / name="C";
keylegend "A" "B";
run;
quit;
Fred_Gavin
Calcite | Level 5
I know this way, but some plots are with many groups, i just dont wanna type them one by one.

I am thinking of stick on the vline statement

vline x / response = y group=grp;

Under this circumstance, anyway to do it?

Thanks
GraphGuy
Meteorite | Level 14
And if sgplot doesn't work out for you, here's how to do it with traditional SAS/Graph proc gplot:


legend1 label=none order=('Low' 'High');

symbol1 value=dot height=.7pct interpol=none c=gray;
symbol2 value=none interpol=join c=green;
symbol3 value=none interpol=join c=brown;

proc gplot data=sashelp.stocks
(where=(date >= "01jan2000"d and stock = "IBM"));
title "Stock Trend";
plot close*date=1 low*date=2 high*date=3 / overlay
legend=legend1;
run;
Fred_Gavin
Calcite | Level 5
my first exposure to SAS graphics is with sg procedures, so i dont know much about traditional SAS/graph procedures. And the output using this is not nice as well.

All my previous works on plots were done in R or Matlab. Since SG procedures are really nice, i try to stick on it for later work.

Thanks.
DanH_sas
SAS Super FREQ
Is your goal to eliminate a group value from your legend?
Fred_Gavin
Calcite | Level 5
Yes, under Vline statement, there will be several plots over time for the groups.

say, total, female, and male. In the legend, I only wanna keep female and male, but eliminate total.

Anyways???

Thanks
Jay54
Meteorite | Level 14
For SAS 9.2, there is no way to remove an item from the legend. You just have to avoid adding it as suggested by Karel. You will need to separate out the groups you don't want in the legend. So, if you want group A, B and C, but not D and E, then you need two VLINE statements, with separate columns. Then, add only the one that you want to the KEYLEGEND statement. By default, CYCLEATTRS will still increment the attributes for each curve.
Fred_Gavin
Calcite | Level 5
Thanks for the reply.

Because there are several variables with different groups in the dataset. I need the calculate the proportion change for each group in each variable. Therefore I developed a macro to calculate , and plot each variable with different group at once.

series statement definitely is not a nice way for my purpose, as I have to input the groups one by one for each variable.

As there is no way to eliminate it.. then I will leave it.

Thanks..
Fred_Gavin
Calcite | Level 5
Also by the way,

for controlling the font in the graphics, is there anyway to handle such change for xaxis, yaxis, legend separtely?

So far I only can find graphlabetext, graphvaluetext and etc., but they change all of them simultaneously.
Jay54
Meteorite | Level 14
SG procedures are designed to surface the most commonly used features of Graph Template Language (GTL) in a procedure syntax. They do not surface all features from GTL. To customize each axis fonts individually, you have to use GTL. As a start, use the procedure option TMPLOUT=filename to get the GTL syntax for your SGPLOT program.

Then, on LAYOUT OVERLAY statement, you can set XAXISOPTS and YAXISOPTS suboptions to set the LABELATTRS= and TICKVALUEATTRS=. Within these options you can set the various font attributes.

On the DISCRETELEGEND statement, you can set TITLEATTRS= and VALUEATTRS= to get the customizations you need.

Note: in GTL, your VLINE statement will be transcoded as SERIESPLOT statement. If you are not familiar with GTL, there are many papers on support web site to get you started. Also, see the GTL users guide under the SAS/GRAPH doc.
Fred_Gavin
Calcite | Level 5
thank u very much indeed
deleted_user
Not applicable
Maybe this way 🙂

data xxx;
set sashelp.stocks
(where=(date >= "01jan2000"d and stock = "IBM"));
grp = "close"; y = close; output;
grp = "low" ; y = low; output;
grp = "close"; z = high; output; /* "high" group masked as "close"*/
run;

proc sort data=xxx;
by grp date;
run;

proc sgplot data=xxx;
title "Stock Trend";
vline date / response = y group=grp;
vline date / response = z group=grp lineattrs=(color=red);
run;
quit;

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
  • 12 replies
  • 7388 views
  • 0 likes
  • 5 in conversation