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

Hi SAS community!

 

I have a question about generating different color combinations for the sgplot. I know it might sound silly but it could really help me a lot!

 

The task is like that:

proc sgplot data= test;
series y=year x=banana /  lineattrs=(color=Red pattern=dot)
                          markerattrs=(color=Red symbol=circlefilled);
series y=year x=strawberry /  lineattrs=(color=black pattern=dot)
                          markerattrs=(color=black symbol=circlefilled);
series y=year x=grape /  lineattrs=(color=blue pattern=dot)
                          markerattrs=(color=blue symbol=circlefilled);
title	"production of fruit by year";
run;

The plot draws several series of lines,

and I JUST want to test for the color of banana line first, with color of red, then green , then blue, etc.etc, as well as the patterns...

I've tried %array and % do_over but cannot make it work...

 

 

Thanks a lot!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

1) Next is a documnentation of available color names in sas:

http://support.sas.com/publishing/authors/extras/62007_Appendix.pdf

 

2) You can run your code with a macro, suplying the color names to check:

%macro check_colors(colr1, colr2, colr3)
   proc sgplot data= test;
     series y=year x=banana /  lineattrs=(color=&colr1 pattern=dot)
                          markerattrs=(color=&colr1 symbol=circlefilled);
     series y=year x=strawberry /  lineattrs=(color=&colr2 pattern=dot)
                          markerattrs=(color=&colr2 symbol=circlefilled);
     series y=year x=grape /  lineattrs=(color=&colr3 pattern=dot)
                          markerattrs=(color=&colr3 symbol=circlefilled);
     title	"production of fruit by year";
  run;
%mend check_colors;
%check_colors(red, black, blue);  /* replace by any other set of 3 color names */

 

View solution in original post

1 REPLY 1
Shmuel
Garnet | Level 18

1) Next is a documnentation of available color names in sas:

http://support.sas.com/publishing/authors/extras/62007_Appendix.pdf

 

2) You can run your code with a macro, suplying the color names to check:

%macro check_colors(colr1, colr2, colr3)
   proc sgplot data= test;
     series y=year x=banana /  lineattrs=(color=&colr1 pattern=dot)
                          markerattrs=(color=&colr1 symbol=circlefilled);
     series y=year x=strawberry /  lineattrs=(color=&colr2 pattern=dot)
                          markerattrs=(color=&colr2 symbol=circlefilled);
     series y=year x=grape /  lineattrs=(color=&colr3 pattern=dot)
                          markerattrs=(color=&colr3 symbol=circlefilled);
     title	"production of fruit by year";
  run;
%mend check_colors;
%check_colors(red, black, blue);  /* replace by any other set of 3 color names */

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1 reply
  • 675 views
  • 1 like
  • 2 in conversation