BookmarkSubscribeRSS Feed
lueryy2000
Calcite | Level 5
Hello,

I want to apply the color defined in my pattern statement to the pie chart. Below is my data:

data temp;
input group $ count percent color $;
datalines;
G3 179 37 CX191714
A1 138 28 CX26251F
G1 114 23 CX33322E
M 36 7 CX8C7962
A2 17 3 CX806A2B
G2 2 0 CX8C887A
G4 2 0 CXA69F7A
A 0 0 CXA6A18A
D 0 0 CXBFB2B5
E 0 0 CXFFFFFF
;
run;

The last column is the color code I define by myself. However, when I used the following code to draw the pie chart for group. SAS used some other colors instead of my color list. Below is my code:

data _null_;
set temp;
CALL SYMPUT('SliceColor'!!TRIM(LEFT('_N_')),TRIM(LEFT(COLOR)));
RUN;

%MACRO PatternStatements;
%DO i=1 %TO 10;
pattern&i V=PSOLID COLOR=&&SliceColor&i;
%END;
%MEND;
%PatternStatements;

PROC GCHART DATA=temp;
PIE group / SUMVAR=COUNT NOHEADING SLICE=OUTSIDE VALUE=NONE PERCENT=NONE DESCENDING OTHER=0;
RUN;
QUIT;

SAS log didn't give any error message but when I call patternstatements macro, log gave this:

MPRINT(PATTERNSTATEMENTS): pattern1 V=PSOLID COLOR=CXD9892B;
MPRINT(PATTERNSTATEMENTS): pattern2 V=PSOLID COLOR=CXD9576E;
MPRINT(PATTERNSTATEMENTS): pattern3 V=PSOLID COLOR=CXFFFFFF;
MPRINT(PATTERNSTATEMENTS): pattern4 V=PSOLID COLOR=CX769966;
MPRINT(PATTERNSTATEMENTS): pattern5 V=PSOLID COLOR=CX8C411C;
MPRINT(PATTERNSTATEMENTS): pattern6 V=PSOLID COLOR=CX99FFFF;
MPRINT(PATTERNSTATEMENTS): pattern7 V=PSOLID COLOR=CX9999FF;
MPRINT(PATTERNSTATEMENTS): pattern8 V=PSOLID COLOR=CXFFFF99;
MPRINT(PATTERNSTATEMENTS): pattern9 V=PSOLID COLOR=CX999999;
MPRINT(PATTERNSTATEMENTS): pattern10 V=PSOLID COLOR=CX99FF99;

This is not my list defined in the pattern statement. I really couldn't understand how this happened. Does anyone give me some help? Thank you very much.

Lu
2 REPLIES 2
GraphGuy
Meteorite | Level 14
The main problem is that you'll want to *not* have the _n_ in quotes, when you're looping through creating your macro variables with symput. You'll also probably want to sort your data set, to guarantee that the pattern statements match up with the order the items will appear in the legend.




proc sort data=temp out=temp;
by group;
run;
data _null_;
set temp;
CALL SYMPUT('SliceColor'||TRIM(LEFT(_N_)),TRIM(LEFT(COLOR)));
RUN;

%MACRO PatternStatements;
%DO i=1 %TO 10;
pattern&i V=PSOLID COLOR=&&SliceColor&i;
%END;
%MEND;
%PatternStatements;

title "&slicecolor1 &slicecolor2";
PROC GCHART DATA=temp;
PIE group / SUMVAR=COUNT
NOHEADING
SLICE=OUTSIDE
VALUE=NONE
PERCENT=NONE
DESCENDING
legend
OTHER=0;
RUN; QUIT;
lueryy2000
Calcite | Level 5
Ooops, I made such a silly mistake. Now it works perfectly. Thank you very much for your help and suggestion.
Lu

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
  • 2 replies
  • 801 views
  • 0 likes
  • 2 in conversation