Reputation: 1089
This is related to my previous question : Escape characters interpreted as array in SAS
I have managed to create the variable with special character (despite not a good practice, this is required).
Now I am trying to plot the respective variable using sgplot, but again having a difficulty to fetch the Age(years) variable , as it contains the special character of array ( )
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;
In the above code, sgplot does not work because of the following line
yaxistable Gender 'Age(years)'n /
labelattrs=GraphUnicodeText(weight=bold size=9pt)
labelhalign=center position=left location=outside;
The aim is to display 'Age(years)' in the graph.
How can I allow the yaxistable of sgplot to read 'Age(years)' as a variable and display this correctly on the graph?
Upvotes: 0
Views: 407
Reputation: 1792
How about this?
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;
Edit: this can then of course be simplified as
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;
Upvotes: 1