0
votes

I am trying to create a scatter plot with group by condition. In the below example I have some data points(of continuous variable) are common between the categorical variable MAKE. So the data points are getting overlayed which is making me not to identify if the graph represents presence of both the variables or just one.

How to avoid it by either using two different symbols in SGPLOT procedure, like the way we can use in GPLOT . Sample code of SGPLOT I used:

proc sgplot data=sashelp.cars(where=(make in ('Dodge', 'Chrysler')));
scatter Y=mpg_city X=mpg_highway / group=make markerattrs=(symbol=plus);
run;

I know that the below code works, but I want to use SGPLOT instead of GPLOT:

ods listing close;
SYMBOL1 VALUE=dot color=bib; 
SYMBOL2 VALUE=square color=brown;
proc gplot data=sashelp.cars(where=(make in ('Dodge', 'Chrysler')));
plot mpg_city * mpg_highway =make ;
run;

Thanks in advance.

1

1 Answers

1
votes

Well, of course it's using one symbol. You told it to!

Either remove your MARKERATTR=(symbol= code, or use MARKERCHAR to have it come from a variable or an attribute map dataset (DATTRMAP) to specify it that way, if you want to be able to specify the two markers specifically. Or use color.

Here are a few examples:

*Using MARKERCHAR;
data cars;
  set sashelp.cars;
  if make = 'Dodge' then marker_char = '+';
  else if make = 'Chrysler' then marker_char = 'o';
  else delete;
run;

proc sgplot data=cars(where=(make in ('Dodge', 'Chrysler')));
scatter Y=mpg_city X=mpg_highway / group=make markerchar=marker_char;
run;


*Using an attribute map (most similar to the GPLOT example);
data attr_map;
  length value markercolor $8;
  id='MakeAttr';
  value = 'Dodge';
  markersymbol='plus';
  markercolor='green';
  output;
  value='Chrysler';
  markersymbol='circle';
  markercolor='red';
  output;
run;


ods html style=htmlblue;
proc sgplot data=sashelp.cars(where=(make in ('Dodge', 'Chrysler'))) dattrmap=attr_map;
scatter Y=mpg_city X=mpg_highway / group=make attrid=MakeAttr;
run;