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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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