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;
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.
Yes, look into attribute maps:
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;
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.
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.