Hello all,
I'm trying to change the size of a scatterplot to show a 7x7 grid (a total of 49 cells), instead of what the scatterplot automatically generates. Can anyone tell me how I can change the amount of squares on the grid?
Also, I'm needing help trying to define how many data points (point count) in each square on the grid by producing a data table
Thanks in advance,
Aerianna
@Aerianna9 wrote:
This was helpful for the grid. Now I'm needing help with the point count for each grid cell. Any ideas?
One way is to create a custom format for each range of value with the desired boundaries for cells. Then apply that format in procedure to count things.
An example using @Ksharp's example data set modified to create "nicer" cell boundaries:
data have;
call streaminit(123);
do i=1 to 100;
x=rand('uniform')*7;
y=rand('uniform')*7;
output;
end;
run;
proc format; value xcell 0 -<1 = '1' 1 -<2 = '2' 2 -<3 = '3' 3 -<4 = '4' 4 -<5 = '5' 5 -<6 = '6' 6 -<7 = '7' ; value ycell 0 -<1 = '1' 1 -<2 = '2' 2 -<3 = '3' 3 -<4 = '4' 4 -<5 = '5' 5 -<6 = '6' 6 -<7 = '7' ; run; proc sort data=have; by descending y; run; proc tabulate data=have; class x; class y/ order=data; format x xcell. y ycell.; table y, x *n=' ' / misstext='0' ; run;
The 7 x 7 cell boundaries were relatively easy due to the way the data set was made so each variable has values in the [0,7] range. In a more typical fashion you would need to do more work with the formats (and your actual data). This relatively easily is made to match a VALUES option on a graph axis statement.
The sort was so the cell count orientation would match the graph closer.
Example data
What the boundaries of the cells should be.
The code of your current scatterplot.
Typically scatterplots do not have "cells", so you need to provide some sort of example details.
data have;
call streaminit(123);
do i=1 to 100;
x=rand('uniform')*6;
y=rand('uniform')*6;
output;
end;
run;
proc sgplot data=have;
scatter x=x y=y;
xaxis values=(1 to 7 by 1);
yaxis values=(1 to 7 by 1);
run;
@Aerianna9 wrote:
This was helpful for the grid. Now I'm needing help with the point count for each grid cell. Any ideas?
One way is to create a custom format for each range of value with the desired boundaries for cells. Then apply that format in procedure to count things.
An example using @Ksharp's example data set modified to create "nicer" cell boundaries:
data have;
call streaminit(123);
do i=1 to 100;
x=rand('uniform')*7;
y=rand('uniform')*7;
output;
end;
run;
proc format; value xcell 0 -<1 = '1' 1 -<2 = '2' 2 -<3 = '3' 3 -<4 = '4' 4 -<5 = '5' 5 -<6 = '6' 6 -<7 = '7' ; value ycell 0 -<1 = '1' 1 -<2 = '2' 2 -<3 = '3' 3 -<4 = '4' 4 -<5 = '5' 5 -<6 = '6' 6 -<7 = '7' ; run; proc sort data=have; by descending y; run; proc tabulate data=have; class x; class y/ order=data; format x xcell. y ycell.; table y, x *n=' ' / misstext='0' ; run;
The 7 x 7 cell boundaries were relatively easy due to the way the data set was made so each variable has values in the [0,7] range. In a more typical fashion you would need to do more work with the formats (and your actual data). This relatively easily is made to match a VALUES option on a graph axis statement.
The sort was so the cell count orientation would match the graph closer.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: