使用数组符号作为特殊字符的变量绘制SAS sgplot
这与我先前的问题有关: 我已经设法创建了具有特殊字符的变量(尽管不是很好的实践,但这是必需的) 现在,我尝试使用sgplot绘制相应的变量,但是再次难以获取年龄(years)变量,因为它包含数组()的特殊字符 在上面的代码中,sgplot由于以下行而不起作用使用数组符号作为特殊字符的变量绘制SAS sgplot,sas,Sas,这与我先前的问题有关: 我已经设法创建了具有特殊字符的变量(尽管不是很好的实践,但这是必需的) 现在,我尝试使用sgplot绘制相应的变量,但是再次难以获取年龄(years)变量,因为它包含数组()的特殊字符 在上面的代码中,sgplot由于以下行而不起作用 yaxistable Gender 'Age(years)'n / labelattrs=GraphUnicodeText(weight=bold size=9pt) labelhalign=c
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;
出于显示目的,您是否“需要”将该变量称为
Age(years)
?你能不能把变量保持为age\u years
并用标签显示为age(years)
。变量的名称不需要它,而只需要标签。假设我将var重命名为age_years,但如何更改“yaxistable”以使用var“age_years”,并将其显示为标签“age(years)”?如果在表中为变量指定标签,sgplot将在输出报告中默认使用它(参见下面的答案)。另一个选项是使用yaxistable
语句的label=
选项显式显示标签。@user2877959感谢您指出标签!
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;