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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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