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);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.