You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SAS PROC GPLOT中Legend语句ORDER选项报错求助

Fixing the ORDER= Legend Error in SAS Proc GPLOT

Let's break down what's causing your error and how to fix it so you only see the legend entries you want.

Why You're Getting the Error

The ERROR: The ORDER= entry "ExpPred" is not a legend value happens because you're mixing up two parts of the legend statement:

  • You defined custom legend text in the value= parameter ('F' 'S' 'T' 'G' or your longer Polish labels in the commented code)
  • But your order= parameter is referencing variable names ('ExpPred' etc.) instead of the custom text you defined.

SAS looks for exact matches between the order= entries and the actual legend values (either your custom value= text, or variable labels/names if no custom text is set). Since they don't match, it throws an error.

The simplest way to exclude certain variables from the legend is to add the nolegend option to their corresponding symbol definitions. This skips adding them to the legend entirely, so you don't need to mess with order= at all:

ods html file="..." gpath="..."; 
ods graphics on; 
goptions reset=all hsize=24cm vsize=15cm; 
Title; 
axis1 label = none order = (300000 to 1000000 by 100000) value = (angle=0 height=1.5); 
axis2 label = none /* order = (1 to 12 by 1) */ offset = (0.4 cm, 0.4 cm) minor=none value = (angle=0 height=1.5 'sty' 'lut' 'mar' 'kwi' 'maj' 'cze' 'lip' 'sie' 'wrz' 'paź' 'lis' 'gru'); 

-- Keep your first 4 symbols as-is
symbol1 color="Medium Vivid Red" interpol=spline line=1 value=dot height=1.2 width=1; 
symbol2 color="Medium Vivid Blue" interpol=spline line=1 value=dot height=1.2 width=1; 
symbol3 color="Medium Vivid Red" interpol=spline line=3 value=none height=1.2 width=1; 
symbol4 color="Medium Vivid Blue" interpol=spline line=2 value=none height=1.2 width=1; 

-- Add nolegend to the symbols you don't want in the legend
symbol5 color="Medium Vivid Red" interpol=spline line=3 value=none height=1.2 width=1 nolegend; 
symbol6 color="Medium Vivid Blue" interpol=spline line=2 value=none height=1.2 width=1 nolegend; 

-- Remove the order= parameter, or use it to reorder your custom text
legend1 label=none value = (justify= left 'F' 'S' 'T' 'G') frame; 
/* If you want to use your longer labels instead:
legend1 label=none shape=symbol(4,1.25) value = (justify= left 'Prognoza modelem Wintersa' 'Prognoza modelem SARIMA' 'Przedziały ufności (95%) - Model Wintersa' 'Przedziały ufności (95%) - Model SARIMA') frame;
*/

proc gplot data = ltz.ltz_Comp2019; 
plot (ExpPred ArimaPred ExpU95 ArimaU95 ExpL95 ArimaL95)*data / vaxis=axis1 haxis=axis2 legend=legend1 overlay; 
run; 
quit; 

ods graphics off; 
ods html close;

Solution 2: Match order= to Your Custom Legend Values

If you prefer to use the order= parameter, make sure the entries exactly match the text in your value= parameter. For example:

  • For your short labels:
    legend1 order=('F' 'S' 'T' 'G') label=none value = (justify= left 'F' 'S' 'T' 'G') frame;
    
  • For your longer Polish labels:
    legend1 order=('Prognoza modelem Wintersa' 'Prognoza modelem SARIMA' 'Przedziały ufności (95%) - Model Wintersa' 'Przedziały ufności (95%) - Model SARIMA') label=none shape=symbol(4,1.25) value = (justify= left 'Prognoza modelem Wintersa' 'Prognoza modelem SARIMA' 'Przedziały ufności (95%) - Model Wintersa' 'Przedziały ufności (95%) - Model SARIMA') frame;
    

Extra Note About Variable Labels

If your variables have defined LABEL attributes, SAS will use those labels as the default legend values instead of the variable names. If that's the case, you'll need to use the label text in order= instead of the variable name, or add the varlabel option to your plot statement to force SAS to use variable names.

内容的提问来源于stack exchange,提问作者Slynny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:38:08