View Full Version : Another SAS question


a little boy
05-15-2009, 11:46 PM
Hi everyone,

I have another question on plotting the grouped data separately. I used the proc plot and asked SAS to plot two separate plots for group A and B respectively. However when I execute the code below, there is only one group A shown in the plot. I wonder where the group B is ?

Thank you very much !!

data prob23;
length group $ 1;
input x y z group $;
datalines;
2 4 6 A
3 3 3 B
1 3 7 A
7 5 3 B
1 1 5 B
2 2 4 A
5 5 6 A
;
proc plot data = prob23;
plot y*x/vaxis = 0 to 5 by 1;
run;
proc plot data = prob23;
by group;
plot y*x = group/vaxis = 0 to 5 by 1;
run;

lumhearts
05-16-2009, 04:11 PM
Again, here, you do not need that second line of code. And, in order to plot "by group" or any other categorical variable, you must first sort by that variable. Here is an example:

data prob23;
input x y z group $;
datalines;
2 4 6 A
3 3 3 B
1 3 7 A
7 5 3 B
1 1 5 B
2 2 4 A
5 5 6 A
;
proc sort data = prob23;
by group;
run;

proc plot data = prob23;
by group;
plot y*x;

run;