Data visualization with SAS programming

Controlling order of group attributes in SGPLOT

Accepted Solution Solved
Reply
Regular Contributor
Posts: 151
Accepted Solution

Controlling order of group attributes in SGPLOT

Is there a way to tie a group attribute to a formatted value in SGPLOT (a bit like the preloading a format in proc tabulate, I think). In the code example below, I group countries into 'odd' and 'even'. The first plot then represents the odds with blue circle and the evens with a red triangle. In the second plot, one observation is dropped from the data and now the patterns are reversed. Can I code this so that I will get the same pattern for odd and even as my data set changes?

 

data test;
input country  x y flag;
cards;
1 1 2 0
2 2 3 1
3 3 4 1
4 4 5 1
;
proc format;
  value  test 1,3="Odd" 2,4="Even";
proc sgplot data=test;
  format country  test.;
  styleattrs datasymbols=(circlefilled trianglefilled);
  scatter x=x y=y /group=country markerattrs=(size=12) ;
proc sgplot data=test (where=(flag));
  format country  test.;
  styleattrs datasymbols=(circlefilled trianglefilled);
  scatter x=x y=y /group=country markerattrs=(size=12) ;
  run;

Accepted Solutions
Solution
‎04-25-2018 01:53 PM
Super User
Posts: 13,941

Re: Controlling order of group attributes in SGPLOT

Posted in reply to BruceBrad

You need to ensure that the attributes you address are valid for the plot type:

data myattrmap;
length markersymbol $20;
input ID $ value $ markercolor  $ markersymbol $;
datalines;
myid  Odd  blue circle
myid  Even green  trianglefilled
;
run;

proc sgplot data=test dattrmap=myattrmap;
  format country  test.;
  scatter x=x y=y /group=country markerattrs=(size=12) attrid=myid;
run;
proc sgplot data=test (where=(flag)) dattrmap=myattrmap;
  format country  test.;
  scatter x=x y=y /group=country markerattrs=(size=12) attrid=myid ;

run;

 

Fillcolor is more for VBAR and LINECOLOR is for SERIES (which with your data overlay).

The attributes for SCATTER are generally all markerxxxxxxx Such as markersize. If you want a filled symbol you need to specify one that is filled (TRIANGLEFILLED) which will then use the marker color for the fill. Note that you need to make the length of the text variables long enough to hold the text to describe them. The default you used was 8 and could not hold any of the filled symbol names.

View solution in original post


All Replies
Super User
Posts: 24,012

Re: Controlling order of group attributes in SGPLOT

Posted in reply to BruceBrad
Regular Contributor
Posts: 151

Re: Controlling order of group attributes in SGPLOT

Thanks for the suggestion. That does seem to be the way to go. However, in my new code below, the attribute map doesn't seem to have any impact (no error is given either).

data test;
input country  x y flag;
cards;
1 1 2 0
2 2 3 1
3 3 4 1
4 4 5 1
;
proc format;
  value  test 1,3="Odd" 2,4="Even";
data myattrmap;
input ID $ value $ linecolor $ fillcolor $ symbol $;
datalines;
myid  Odd  blue blue circle
myid  Even green green triangle
;
run;

proc sgplot data=test dattrmap=myattrmap;
  format country  test.;
  scatter x=x y=y /group=country markerattrs=(size=12) attrid=myid;
run;
proc sgplot data=test (where=(flag)) dattrmap=myattrmap;
  format country  test.;
  scatter x=x y=y /group=country markerattrs=(size=12) attrid=myid ;
  run;
Solution
‎04-25-2018 01:53 PM
Super User
Posts: 13,941

Re: Controlling order of group attributes in SGPLOT

Posted in reply to BruceBrad

You need to ensure that the attributes you address are valid for the plot type:

data myattrmap;
length markersymbol $20;
input ID $ value $ markercolor  $ markersymbol $;
datalines;
myid  Odd  blue circle
myid  Even green  trianglefilled
;
run;

proc sgplot data=test dattrmap=myattrmap;
  format country  test.;
  scatter x=x y=y /group=country markerattrs=(size=12) attrid=myid;
run;
proc sgplot data=test (where=(flag)) dattrmap=myattrmap;
  format country  test.;
  scatter x=x y=y /group=country markerattrs=(size=12) attrid=myid ;

run;

 

Fillcolor is more for VBAR and LINECOLOR is for SERIES (which with your data overlay).

The attributes for SCATTER are generally all markerxxxxxxx Such as markersize. If you want a filled symbol you need to specify one that is filled (TRIANGLEFILLED) which will then use the marker color for the fill. Note that you need to make the length of the text variables long enough to hold the text to describe them. The default you used was 8 and could not hold any of the filled symbol names.

SAS Super FREQ
Posts: 1,289

Re: Controlling order of group attributes in SGPLOT

[ Edited ]

Make sure group values are correct.  Also, for Symbols, be sure to NOT use HTMLBlue style (for HTML destination).  Use Listing.  Or, set ATTRPRIORITY=none on ODS Graphics statement.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 149 views
  • 3 likes
  • 4 in conversation