Hi All,
I am working on a plot like this: https://blogs.sas.com/content/graphicallyspeaking/2018/03/02/series-plot-varying-attributes/
I am currently struggling with the datastep where I need to define that the last point of the previous curve segment is replicated as the first point of the next segment.
I have two dates defining the change in color. When age (age_measure) passes age 1, then I want a change in the color and again when age passes age 2 a new change in color.
So I need to get the determinant of the colorresponse variable appear twice: Meaning age 1 appears both as colorresponse variabel 1 and 2, and age 2 appearing both as colorresponse variable 2 and 3 to get the datapoints to connect in the plot.
Do you have any ideas on how to define that in a datastep?
Example data below:
patientid = patient id, a1 = age 1, a2 = age 2, visit date = examination date, measure = measurement at examination date, age_measure = age at measurement.
The curve is measure as a function of age_measure, where the curve needs to change color when age 1 and age 2 are passed (interpolated values of age_measure.). Age 1 always comes before age 2, but some patients jump directly to age 2. Some patients might not have either age 1 or 2.
I don't know if this this possible in proc sgplot as the curve needs to "break" several times, like in a spaghetti-plot. But maybe proc gplot works, I have just never used that before.
data patients;
input patientid $ a1 a2;
datalines;
1 32 34
2 23 .
3 22 35
4 30 31
5 . 28
;
data visits;
input patientid $ visit_date :yymmdd8. measure age_measure;
format visit_date yymmdd10.;
datalines;
1 20180101 3.4 20
1 20180505 2.3 35
2 20170210 7.3 15
2 20170217 7.2 24
2 20170220 7.1 35
3 20170221 5.4 33
4 20180202 3.4 30
4 20180204 3.2 37
5 20180504 5.6 28
5 20180505 5.0 32
;
data have;
merge
patients
visits
;
by patientid;
run;
Data example is important.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
And then tell use where the curve change needs to happen.
Dear Ballardw,
I have now updated the question
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.