BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Toronto_Guy
Calcite | Level 5

Hi everyone,

 

This is my first post 

 

I have used these forums for years now to answer a lot of the questions I had.  I have successfully found an answer to all my questions up until this point.  I would like to thank everyone for their great help.

 

However, I am really stuck now and it seems no one has ever asked this question.

 

I would like to be able to format pieces of my curves based on a binary variable that is not used for plotting the curves.  If the value of this variable is 1 then the curves need to be formatted one way and if 0 the curves need to be formatted in a different way.

 

I am attaching an excel file with 2 pictures.  One with the output that is produced from the code given below and the other is a picture of what I would like to have.

 

Here is the relevant code that produces the "Example of output I have".

 

data code;set sys.&project.data;
title "Example";
Axis1 Label = ("Percent") order=(0 to 0.7 by 0.1);
legend1 label = ("Curves");
proc gplot data=code;  
    symbol1 interpol=sm25 height=0.1 value = NONE width = 3 mode = include;
	plot (a b c d)*time /haxis = 0 to 60 by 10 OVERLAY legend
	vaxis = axis1 legend = legend1;
	format a percent5. b percent5. c percent5. d percent5.;
run;
quit;

I am not providing the entire data set as it is 2400 rows.

 

But here is a dummy example of how it looks:

Curve NametimeY-valueBinary Variable
a0.101
a0.20.11
a0.30.21
a0.40.10
a0.50.40
b0.10.251
b0.20.51
b0.30.70
b0.40.2640
b0.50.4160
c0.101
c0.200
c0.301
c0.40.671
c0.500
d0.10.86740
d0.200
d0.30.46741
d0.401
d0.50.64650

 

The time variable goes from 0.1 to 60.  There are 4 curves (a,b,c,d).  The Y-value is a continuous variable that range from 0 - 1.  The binary variable is either 0 or 1.  The data I provided is only an example for time 0.1 - 0.5.

 

Basically what I would like to have as output is shown in the "Example of output I need" picture

 

Essentially wherever the binary variable is 0 the curve is formatted one way and where the binary variable is 1 the curve needs to be formatted differently (in the case of the example it is made thicker).

 

Any thoughts?  I have spent days trying all sorts of work around methods but I can't seem to do this Other than outputting the curves I already have and painstakingly (and very inaccurately) using the brush tool in paint to thicken the curves in the correct spots.  As you can imagine this is very time consuming, inaccurate and just flat out strange and unscientific thing to do.

 

Thanks everyone!

 

 

 

 

 

 

1 ACCEPTED SOLUTION
10 REPLIES 10
Reeza
Super User

One method:

 

1. Switch to SGPLOT - GPLOT is outdated

2. Add a new variable or series that contains the data for where you want the bands

3. Plot the bands using the BAND statement

 

Starter code - needs work to set up the band data properly:

 

 

data have;
input Curve_Name $ time	Y_value	Binary_Variable;
band_data_lower = ifn(binary_variable =1, Y_value - 0.01, .);
band_data_upper = ifn(binary_variable =1, Y_value + 0.01, .);
cards;
a	0.1	0	1
a	0.2	0.1	1
a	0.3	0.2	1
a	0.4	0.1	0
a	0.5	0.4	0
b	0.1	0.25	1
b	0.2	0.5	1
b	0.3	0.7	0
b	0.4	0.264	0
b	0.5	0.416	0
c	0.1	0	1
c	0.2	0	0
c	0.3	0	1
c	0.4	0.67	1
c	0.5	0	0
d	0.1	0.8674	0
d	0.2	0	0
d	0.3	0.4674	1
d	0.4	0	1
d	0.5	0.6465	0
;
run;

proc sgplot data=have;
spline y=y_value x=time /group=curve_name;
band lower=band_data_lower upper=band_data_upper x=time;
run;
Toronto_Guy
Calcite | Level 5

Thanks for the quick reply!

 

I will try to use the suggestions you provided to see if I can come up with the answer

Reeza
Super User

PS. If you want the line underneath the band to show up, play around with the TRANSPARENCY setting for the BAND statement.

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n1t2ihc734azuvn17021ri2cl057.htm&docs...

Reeza
Super User

PS. If you want the line underneath the band to show up, play around with the TRANSPARENCY setting for the BAND statement.

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n1t2ihc734azuvn17021ri2cl057.htm&docs...

 

And you'll want a discrete attribute map to control the colours and line styles

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n03orofvtqwhhon1kkn76l1ovjkx.htm&docs...

WarrenKuhfeld
Rhodochrosite | Level 12

I agree with @Reeza .  I would add though that the GPLOT smoothing splines are not available in SGPLOT.  SGPLOT provides better methods (IMHO) including PBSPLINE (penalized B-spline). If you want smoothing splines, you can get the values out of PROC TRANSREG. 

http://go.documentation.sas.com/?docsetId=statug&docsetTarget=statug_transreg_details08.htm&docsetVe...

Jay54
Meteorite | Level 14

SGPLOT with SAS 9.40M3 does support SPLINE statement.  Not sure if this will work for you.

Jay54
Meteorite | Level 14

There is no way to change the attributes of a single curve (Series) based on another variable.  So, if you want the curve to "appear" to change attributes (color, thickness), you will need to break it up into segments, each having a unique group value.  Each segment should include the connected point in both groups.  Then, you can display the series by group with different attributes.  You can use a Discrete Attributes Map" to specify the attributes for each group segment.

Toronto_Guy
Calcite | Level 5

Thank you all for the replies.

 

I will try to include these recommendations and will report back with results

Toronto_Guy
Calcite | Level 5

Wow this is so awesome.  I feel so special 🙂

 

Thank you for letting me know and for all the help provided by everyone else.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 10 replies
  • 1119 views
  • 5 likes
  • 4 in conversation