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);
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.