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

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 -

 

RafiRahi_0-1598673178375.png

 

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;



Annotation 2020-08-29 050758.png

 

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. 

Rafi Rahi
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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;

 

View solution in original post

4 REPLIES 4
RafiRahi
Fluorite | Level 6
Thank you very much draycut for looking into my question. I am very happy to tell you that the problem is solved now after applying Rick's suggestion. My data structure was exactly the same as Rick provided (obviously different variable names).
Rafi Rahi
Rick_SAS
SAS Super FREQ

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;

 

RafiRahi
Fluorite | Level 6
Dear Rick, I cannot thank you enough for this solution, it straightway did the job for me! Considering the time line pressure I was in, you just made my day. Thank you so much!
Rafi Rahi

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2158 views
  • 3 likes
  • 3 in conversation