BookmarkSubscribeRSS Feed
DB_ECON
Calcite | Level 5
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
4 REPLIES 4
GraphGuy
Meteorite | Level 14
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;
DB_ECON
Calcite | Level 5
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...
DanH_sas
SAS Super FREQ
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;
GraphGuy
Meteorite | Level 14
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1633 views
  • 0 likes
  • 3 in conversation