BookmarkSubscribeRSS Feed
Manj
Fluorite | Level 6

 

I have the following plot where i need to increase the width of the line in legend. I have tried using LEGENDITEM and KEYLEGEND , but it gives error when i use LEGENDITEM. Is there a way to increase the line in the legend marked in the figure?

 

Manj_0-1653673363648.png

My code and the error below:


proc sgplot data=xxx dattrmap=myattr noautolegend;
scatter x=avisn y=aval_median / group=trt01a yerrorlower=aval_p5 yerrorupper=aval_p95 attrid=trt01a ;
series x=avisn y=aval_median /group=trt01ax attrid=trt01ax name="lgnd1" ;


refline 1.35 / axis=y label="1.35 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=solid color=grey thickness=0.01);

refline 0.65 / axis=y label="0.65 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=longdash color=grey thickness=0.01);

refline 0.166 / axis=y label="0.166 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=shortdash color=grey thickness=0.01);

xaxis values=(5 to 42 by 1) valuesdisplay=("Week 5" "Week 6" "" "" "Week 9" "Week 10" "" "" "" "" "" "" "Week 17" "Week 18" "" "" "" "" "" "" "Week 25" "Week 26" "" "" "" "" "" "" "Week 33" "Week 34" "" "" "" "" "" "" "Week 41" "") label= 'Weeks from Randomization'
Valuesrotate=Diagonal fitpolicy=rotatethin valueattrs=(size=7);

yaxis label="Plasma CCC (mcg/mL)" TYPE=LOG LOGSTYLE=LOGEXPAND LOGBASE=10;

legenditem type=markerline name="lgnditm" / lineattrs=(color=bib pattern=1 thickness=5);

keylegend "lgnd1" "lgnditm" /title="" ;
run;


******************ERROR below*************

Manj_0-1653675114266.png

 

 

9 REPLIES 9
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
Manj
Fluorite | Level 6
LINELENGTH adjusts the length of the line, Waht I need is the width of the line to be increased.
ballardw
Super User

You would use options for KEYLEGEND of TITLEATTRS=(<options>) to set text size and appearance for the title text of the legend and VALUEATTRS=(<options>) to change the text size and appearance of the values.

 

Please when posting things related to errors copy the code and all the messages for the procedure or data step, then on the forum open a text box using the </> icon and paste all the text.

 

If the code is in a macro then set OPTIONS MPRINT; before executing the macro and copy and paste the text from the log (yes it will be a tad long).

 

One reason to ask for ALL the text is because the Error you have shown has nothing to do with either Keylegend or Legenditem but with a LABEL statement that you do not even show in your "code".

Manj
Fluorite | Level 6

Hi,
i dont want to do anything with the text or values and hence Titleattrs and valueattrs doesnt apply, all i want is to increase the width of the line in the legend . The error shows about legenditem only, for better visibility, i have pasted the 'image' of the error message.

DanH_sas
SAS Super FREQ

What version of SAS are you using (including maintenance version)?

Manj
Fluorite | Level 6
SAS 9.4.
Below is what I see in the logs:

NOTE: Copyright (c) 2002-2012 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M3)
DanH_sas
SAS Super FREQ

The LEGENDITEM statement was not introduced in the SG procedures until 9.4 (maintenance level 5), so that is why you are getting the error. However, it is available to you at the GTL level. You temporarily remove the LEGENDITEM option from your SGPLOT code and use TMPLOUT to generate the GTL code. Then, add the LEGENDITEM statement to the GTL code and use the SGRENDER procedure to render the template.

 

Let me know if you need any more details on how to do this.

 

Hope this helps!

Dan

Manj
Fluorite | Level 6
Hi,
Thanks for the suggestion, I have updated my code as below:
The below code error free outputs but have 3 warnings:

WARNING: The ScatterPlot statement named 'lgnd1' will not be drawn because one or more of the required arguments were not supplied.
WARNING: The SeriesPlot statement named 'lgnd2' will not be drawn because one or more of the required arguments were not supplied.
WARNING: A blank graph is produced. For possible causes, see the graphics template language documentation.

.When I try to give legend item , it gives the following error:

ERROR 180-322: Statement is not valid or it is used out of proper order.

how can i update this with increased line width in the legend ?


*************************************************************************code below: **************************************

ods listing close;
ods pdf file="&g_outfile..&g_fontsize" nobookmarkgen style=idsl dpi=600;



proc sgplot data=&G_DDDATASETNAME dattrmap=myattr noautolegend tmplout='temp.txt';

scatter x=avisn y=aval_median / group=trt01a yerrorlower=aval_p5 yerrorupper=aval_p95 attrid=trt01a name="lgnd1" ;
series x=avisn y=aval_median /group=trt01ax attrid=trt01ax name="lgnd2";

refline 1.35 / axis=y label="1.35 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=solid color=grey thickness=0.01);

refline 0.65 / axis=y label="0.65 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=longdash color=grey thickness=0.01);

refline 0.166 / axis=y label="0.166 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=shortdash color=grey thickness=0.01);

xaxis values=(5 to 42 by 1) valuesdisplay=("Week 5" "Week 6" "" "" "Week 9" "Week 10" "" "" "" "" "" "" "Week 17" "Week 18" "" "" "" "" "" "" "Week 25" "Week 26" "" "" "" "" "" "" "Week 33" "Week 34" "" "" "" "" "" "" "Week 41" "") label= 'Weeks from Randomization' Valuesrotate=Diagonal fitpolicy=rotatethin valueattrs=(size=7);

yaxis label="Plasma CAB (mcg/mL)" TYPE=LOG LOGSTYLE=LOGEXPAND LOGBASE=10;

*legenditem name="lgnd2" / lineattrs=(color=orange pattern=1 thickness=5) ;

keylegend "lgnd2" /title="" ;
run;


options nofmterr;
data dddata.xx _null_;
infile 'temp.txt';
input;
_infile_ = tranwrd(_infile_, 'statgraph sgplot', 'statgraph axistables');
_infile_ = tranwrd(_infile_, 'columnweights=preferred','columnweights=(0.2 0.1 0.4 0.15 0.15)');
call execute(_infile_);
run;

proc sgrender data=sashelp.class template=axistables;
run;

ods pdf close;
ods listing;

Manj
Fluorite | Level 6

The below code error free outputs but have 3 warnings:

WARNING: The ScatterPlot statement named 'lgnd1' will not be drawn because one or more of the required arguments were not supplied.
WARNING: The SeriesPlot statement named 'lgnd2' will not be drawn because one or more of the required arguments were not supplied.
WARNING: A blank graph is produced. For possible causes, see the graphics template language documentation.

.When I try to give legend item , it gives the following error:

ERROR 180-322: Statement is not valid or it is used out of proper order.

how can i update this with increased line width in the legend ?


*************************************************************************code below: **************************************

ods listing close;
ods pdf file="&g_outfile..&g_fontsize" nobookmarkgen style=idsl dpi=600;



proc sgplot data=&G_DDDATASETNAME dattrmap=myattr noautolegend tmplout='temp.txt';

scatter x=avisn y=aval_median / group=trt01a yerrorlower=aval_p5 yerrorupper=aval_p95 attrid=trt01a name="lgnd1" ;
series x=avisn y=aval_median /group=trt01ax attrid=trt01ax name="lgnd2";

refline 1.35 / axis=y label="1.35 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=solid color=grey thickness=0.01);

refline 0.65 / axis=y label="0.65 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=longdash color=grey thickness=0.01);

refline 0.166 / axis=y label="0.166 mcg/mL" labelpos=max labelloc=inside labelattrs=(size=7 color=grey) lineattrs=(pattern=shortdash color=grey thickness=0.01);

xaxis values=(5 to 42 by 1) valuesdisplay=("Week 5" "Week 6" "" "" "Week 9" "Week 10" "" "" "" "" "" "" "Week 17" "Week 18" "" "" "" "" "" "" "Week 25" "Week 26" "" "" "" "" "" "" "Week 33" "Week 34" "" "" "" "" "" "" "Week 41" "") label= 'Weeks from Randomization' Valuesrotate=Diagonal fitpolicy=rotatethin valueattrs=(size=7);

yaxis label="Plasma CAB (mcg/mL)" TYPE=LOG LOGSTYLE=LOGEXPAND LOGBASE=10;

*legenditem name="lgnd2" / lineattrs=(color=orange pattern=1 thickness=5) ;

keylegend "lgnd2" /title="" ;
run;


options nofmterr;
data dddata.xx _null_;
infile 'temp.txt';
input;
_infile_ = tranwrd(_infile_, 'statgraph sgplot', 'statgraph axistables');
_infile_ = tranwrd(_infile_, 'columnweights=preferred','columnweights=(0.2 0.1 0.4 0.15 0.15)');
call execute(_infile_);
run;

proc sgrender data=sashelp.class template=axistables;
run;

ods pdf close;
ods listing;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 1904 views
  • 1 like
  • 4 in conversation