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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 894 views
  • 0 likes
  • 3 in conversation