SAS sgplot 使用变量和数组符号作为特殊字符



这与我之前的问题有关:在SAS中解释为数组的转义字符

我已经设法创建了具有特殊字符的变量(尽管这不是一个好的做法,但这是必需的(。

现在我正在尝试使用 sgplot 绘制相应的变量,但再次难以获取 Age(年( 变量,因为它包含数组 ( ( 的特殊字符

data have;
input Name $ Gender $ Age_years Health $;
datalines;
Dino male 6 sick
Rita female 5 healthy
Aurora female 4 healthy
Joko male 3 sick
;
run;

options validvarname=any;
data want;
set have;
'Age(years)'n=Age_years; 
run;
options validvarname=any;
ods graphics / reset width=4in height=3in;
proc sgplot data=want noautolegend;
*Error occurs here*;  
yaxistable Gender 'Age(years)'n / 
labelattrs=GraphUnicodeText(weight=bold size=9pt) 
labelhalign=center position=left location=outside; 
*Error occurs here*;
scatter y='Age(years)'n x=Health;
xaxis offsetmin=0.1 offsetmax=1 label="Health Status" 
labelattrs=GraphUnicodeText(weight=bold size=9pt) ;
yaxis offsetmax=0.1 display=none;
run;

在上面的代码中,sgplot 由于以下行而不起作用

yaxistable Gender 'Age(years)'n / 
labelattrs=GraphUnicodeText(weight=bold size=9pt) 
labelhalign=center position=left location=outside;

目的是在图表中显示"年龄(岁("。

如何允许 sgplot 的 yaxistable 将"年龄(年("读取为变量并将其正确显示在图形上?

这个怎么样?

data have;
input Name $ Gender $ Age_years Health $;
datalines;
Dino male 6 sick
Rita female 5 healthy
Aurora female 4 healthy
Joko male 3 sick
;
run;

options validvarname=any;
data want;
set have;
label age_years='Age(years)'; /*only line changed from your code*/
run;
options validvarname=any;
ods graphics / reset width=4in height=3in;
proc sgplot data=want noautolegend;
yaxistable Gender age_years / 
labelattrs=GraphUnicodeText(weight=bold size=9pt) 
labelhalign=center position=left location=outside; 
scatter y=age_years x=Health;
xaxis offsetmin=0.1 offsetmax=1 label="Health Status" 
labelattrs=GraphUnicodeText(weight=bold size=9pt) ;
yaxis offsetmax=0.1 display=none;
run;

编辑:这当然可以简化为

data want;
input Name $ Gender $ Age_years Health $;
label age_years='Age(years)';
datalines;
Dino male 6 sick
Rita female 5 healthy
Aurora female 4 healthy
Joko male 3 sick
;
run;
ods graphics / reset width=4in height=3in;
proc sgplot data=want noautolegend;
yaxistable Gender age_years / 
labelattrs=GraphUnicodeText(weight=bold size=9pt) 
labelhalign=center position=left location=outside; 
scatter y=age_years x=Health;
xaxis offsetmin=0.1 offsetmax=1 label="Health Status" 
labelattrs=GraphUnicodeText(weight=bold size=9pt) ;
yaxis offsetmax=0.1 display=none;
run;

最新更新