BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RedBishop
Fluorite | Level 6

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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);

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

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);
RedBishop
Fluorite | Level 6
Fantastic, thank you @FreelanceReinhard

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 662 views
  • 1 like
  • 2 in conversation