Dear community,
The below code successfully draws 4 polygons of fill colours red, blue, green, and yellow, respectively.
proc sgplot data=MyData aspect=1 noborder nowall noautolegend sganno=MyData subpixel;
styleattrs datacolors=(red blue green yellow);
polygon x=x y=y id=id / fill nooutline group=id;
xaxis display=none;
yaxis display=none;
run;I am trying to replace the hardcoded colours by a variable of a different dataset, like so:
styleattrs datacolors=(OtherDataSet.colours);(where OtherDataSet.colours neatly has 4 observations being: red blue green yellow)
However, it fails with the error: "Syntax error, expecting one of the following: a name, a quoted string."
Is there something obvious I am missing?
Thanks so much for your help!
Hello @RedBishop,
The DATACOLORS= option requires a space-separated list of colors. So, the solution is to create such a list from OtherDataSet.colours, store it in a macro variable and refer to this macro variable in the PROC SGPLOT step:
proc sql noprint;
select colourname into :mycolours separated by ' ' /* replace "colourname" with the appropriate variable name */
from OtherDataSet.colours;
quit;
styleattrs datacolors=(&mycolours);
Hello @RedBishop,
The DATACOLORS= option requires a space-separated list of colors. So, the solution is to create such a list from OtherDataSet.colours, store it in a macro variable and refer to this macro variable in the PROC SGPLOT step:
proc sql noprint;
select colourname into :mycolours separated by ' ' /* replace "colourname" with the appropriate variable name */
from OtherDataSet.colours;
quit;
styleattrs datacolors=(&mycolours);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.