Data visualization with SAS programming

Label data points and plot multiple series

Reply
Contributor
Posts: 20

Label data points and plot multiple series

Data : 4 variables....x, y, z1 and z2.
Objective plot x against y where z2=1 and plot x against y for z2=2 on the same graph. Also use z1 to label the data points on each plot.
x y z1 z2
1 2 a 1
2 4 b 1
3 5 c 1
4 9 a 2
5 4 b 2
6 8 c 2
SAS Employee
Posts: 967

Re: Label data points and plot multiple series

Perhaps something like this?...


data foo;
input x y z1 z2;
if (z2 eq 1) then line1=y;
if (z2 eq 2) then line2=y;
datalines;
1 2 a 1
2 4 b 1
3 5 c 1
4 9 a 2
5 4 b 2
6 8 c 2
;
run;
symbol1 v=dot i=join c=red;
symbol2 v=dot i=join c=blue;
proc gplot data=foo;
plot line1*x line2*x / overlay;
run;
Contributor
Posts: 20

Re: Label data points and plot multiple series

But what if I already have he data in a sas dataset and there are multiple sub categories. Is an 'if then' statement in a separate data step the only way to go...in which caseI wil have to write multiple if then statements..and where is the label option in your code...

thanks a lot...
SAS Super FREQ
Posts: 889

Re: Label data points and plot multiple series

If you are using SAS 9.2, this is straightforward using PROC SGPLOT:

data somedata;
input x y z1 $ z2;
datalines;
1 2 a 1
2 4 b 1
3 5 c 1
4 9 a 2
5 4 b 2
6 8 c 2
;
run;

proc sgplot data=somedata;
series x=x y=y / group=z2 datalabel=z1;
run;
SAS Employee
Posts: 967

Re: Label data points and plot multiple series

Or something like this?...

data somedata;
input x y z1 $ z2;
datalines;
1 2 a 1
2 4 b 1
3 5 c 1
4 9 a 2
5 4 b 2
6 8 c 2
;
run;

symbol1 v=dot i=join c=red;
symbol2 v=dot i=join c=blue;
proc gplot data=somedata;
plot y*x=z2;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 160 views
  • 0 likes
  • 3 in conversation