BookmarkSubscribeRSS Feed
pdiff
Obsidian | Level 7

I am trying to create a plot using sgplot and scatter that will color code data points based on the value of an endogenous variable. I used to do this through SAS Insight, but that is gone.  I thought I could do it through attribute maps, but I am getting errors.  In the code below I am plotting 6 values (x,y pairs) color coding by the value of x.  Is there a better/easier way to do this.  Please excuse the rough state of the code.

SAS 9.4 64 bit TS1M1

Windows 7 under Mac Book Pro (Yosemite 10.10.3): Parallels 10.2.1

Thanks for any help on this.

Bill

data attrib (drop=x red green blue) ;

  format red green blue hex2. ;

  length linecolor $8 fillcolor $8;

  input @1 x  @1 value$ y;

  ID = 'Test';

  red = int((x/48)*255);

  green = 0;

  blue=255 - red;

  fillcolor= cats('CX',put(red, hex2.),put(green, hex2.),put(blue, hex2.));

  linecolor='Black';

  cards;

  1.5 64

  3 57

  6 48

  12 29

  24 13

  48 2

  ;

run;

data trial ;

  input x y;

  cards;

  1.5 64

  3 57

  6 48

  12 29

  24 13

  48 2

  ;

run;

proc sgplot  data=trial DATTRMAP=attrib;

  scatter x=x y=y/FILLEDOUTLINEDMARKERS markerattrs=(symbol=circlefilled size=10) group=x ATTRID=Test;

run;


5 REPLIES 5
pdiff
Obsidian | Level 7

Update:

I managed to get this to work by:

1) Removing the FILLEDOUTLINEDMARKERS option

2) Changing the attribute variable name "fillcolor" to "MarkerColor".

Is there a list of keyword for attribute map variables?

Also, what if I still wanted outlined markers?

Thanks again,

Bill

Cynthia_sas
SAS Super FREQ

Hi:

  There is a section in the ODS Graphics doc for the SG Procedures that discusses Attribute Maps and shows the list of reserved variable names:

SAS(R) 9.4 ODS Graphics: Procedures Guide, Fourth Edition (the specific link with reserved variables)

and

SAS(R) 9.4 ODS Graphics: Procedures Guide, Fourth Edition (the top link that shows all the sections)

cynthia

DR_Majeti
Quartz | Level 8

Hi Bill,

Do you have Mock, that will be helpful to us to give correct options can be used.

Yes if you need symbols to present, you have to use markercolor.

Thanks,'

Durga.

Jay54
Meteorite | Level 14

What you need is a color response based on a variable. 

COLORRESPONSE is supported for both SCATTER and BUBBLE starting from SAS 9.4(TS1M2).  You are using TS1M1, so that option is not available.  However, these options are available in GTL in TS1M1. 

An easy way to get started would be to run the SGPLOT procedure as you have, and set TMPLOUT="FileName.sas"  SGPLOT will write the generated GTL template program to this file name.  Template name will be "SGPLOT".  Go to the ScatterPlot statement as add the option MARKERCOLORGRADIENT=variable.  You can also use the COLORMODEL option to get the colors you want, or use DISCERTEATTRMAP to get full control on colors and values.

You will need to use the following statement to run the graph from template. 

proc sgrender data=foo template=sgplot;

run;

pdiff
Obsidian | Level 7

Sanjay and others,

        Thank you very much for your help with this. Excellent answers as usual.  I will also look into upgrading to TS1M2.

Bill Price

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2990 views
  • 3 likes
  • 4 in conversation