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 Name | time | Y-value | Binary Variable |
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 |
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!
See new Graphically Speaking article inspired by your query.
https://blogs.sas.com/content/graphicallyspeaking/2018/03/02/series-plot-varying-attributes/
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;
Thanks for the quick reply!
I will try to use the suggestions you provided to see if I can come up with the answer
PS. If you want the line underneath the band to show up, play around with the TRANSPARENCY setting for the BAND statement.
PS. If you want the line underneath the band to show up, play around with the TRANSPARENCY setting for the BAND statement.
And you'll want a discrete attribute map to control the colours and line styles
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.
SGPLOT with SAS 9.40M3 does support SPLINE statement. Not sure if this will work for you.
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.
Thank you all for the replies.
I will try to include these recommendations and will report back with results
See new Graphically Speaking article inspired by your query.
https://blogs.sas.com/content/graphicallyspeaking/2018/03/02/series-plot-varying-attributes/
Wow this is so awesome. I feel so special 🙂
Thank you for letting me know and for all the help provided by everyone else.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: