BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BruceBrad
Lapis Lazuli | Level 10

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
BruceBrad
Lapis Lazuli | Level 10

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;
ballardw
Super User

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.

Jay54
Meteorite | Level 14

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 3862 views
  • 3 likes
  • 4 in conversation