Dear All,
I am reaching out to you to find guidance with the following plot. I want to produce a plot that should look like this -
The white box in the bar means the period when patient did not take any treatment. Interesting thing about each bar is that you will find the therapies in chronological order as the patient took in the past. For example – patient 1005 took Platinum containing therapies for about 180 days, then was off treatment, then took Docetaxel, then off treatment again, then briefly took Other chemotherapy followed by another break, then ICI therapy and then another gap.
I have used the following SGPLOT and the generated plot is given below.
PROC SGPLOT DATA=final;
VBAR subjid / RESPONSE=theradur GROUP=theracat GROUPORDER=data;
XAXIS DISCRETEORDER=DATA LABEL = "Subject";;
YAXIS VALUES = (0 TO 2000 BY 100) LABEL= "Treatment duration, Weeks";
RUN;
Problem is in my plot is not maintaining the sequence of therapies taken in different period and its putting duplicate categories into one category. For example – all the gap period for a patient are put together under gap box, rather than displaying them separately in the bar as they happened in different time period.
Can anyone please advise me how I can get the desired output, especially if the patient has multiple off treatment periods (gaps) between active treatment periods, how I can display these off treatment periods as the order as they happened in the bar. Similarly if the patent took multiple ICI therapies in different period, I would like to display these different ICI therapies as different box in the bar and their order should be as they happened in the past.
Many thanks for looking into this and I look forward to your kind guidance.
A stacked bar chart is for plotting a categorical variable. As such, it assumes that the order of the categories do not vary from bar to bar.
I believe you can achieve your result by switching to a HIGHLOW plot. These are used a lot in clinical graphs. Two examples to get you started are
Here's an example with fake data to get you started:
data Patients;
length Event $ 10;
input ID StartTime EndTime Event;
datalines;
101 0 100 A
101 100 210 B
101 210 380 A
101 380 600 C
101 600 900 B
101 900 1300 A
201 0 300 B
201 300 410 D
201 410 500 A
301 0 80 D
301 80 320 C
301 320 680 A
;
proc sgplot data=Patients;
highlow x=ID low=StartTime high=EndTime / group=Event type=Bar;
xaxis type=discrete;
run;
Can you post some sample of your data?
A stacked bar chart is for plotting a categorical variable. As such, it assumes that the order of the categories do not vary from bar to bar.
I believe you can achieve your result by switching to a HIGHLOW plot. These are used a lot in clinical graphs. Two examples to get you started are
Here's an example with fake data to get you started:
data Patients;
length Event $ 10;
input ID StartTime EndTime Event;
datalines;
101 0 100 A
101 100 210 B
101 210 380 A
101 380 600 C
101 600 900 B
101 900 1300 A
201 0 300 B
201 300 410 D
201 410 500 A
301 0 80 D
301 80 320 C
301 320 680 A
;
proc sgplot data=Patients;
highlow x=ID low=StartTime high=EndTime / group=Event type=Bar;
xaxis type=discrete;
run;
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 25. 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.