<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PROC SGPLOT - How to keep the order of events in stack bar as they are in dataset in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680190#M20430</link>
    <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you can&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;achieve your result by switching to &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://blogs.sas.com/content/graphicallyspeaking/2014/06/16/grouped-timeline/" target="_self"&gt;a HIGHLOW plot&lt;/A&gt;&lt;SPAN style="font-family: inherit;"&gt;. These are used a lot in clinical graphs. Two examples to get you started are&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2014/06/22/swimmer-plot/" target="_self"&gt;Swimmer plots&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2013/01/30/ae-timeline-by-name/" target="_self"&gt;Adverse events plots&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here's an example with fake data to get you started:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 29 Aug 2020 10:34:31 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2020-08-29T10:34:31Z</dc:date>
    <item>
      <title>PROC SGPLOT - How to keep the order of events in stack bar as they are in dataset</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680179#M20428</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am reaching out to you to find guidance with the following plot. I want to produce a plot that should look like this -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RafiRahi_0-1598673178375.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48778iA3C60103846C085A/image-size/large?v=v2&amp;amp;px=999" role="button" title="RafiRahi_0-1598673178375.png" alt="RafiRahi_0-1598673178375.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have used the following SGPLOT and the generated plot is given below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SGPLOT DATA=final;

&amp;nbsp; VBAR subjid / RESPONSE=theradur GROUP=theracat&amp;nbsp; GROUPORDER=data;


&amp;nbsp; XAXIS DISCRETEORDER=DATA LABEL = "Subject";;
&amp;nbsp; YAXIS VALUES = (0 TO 2000 BY 100) LABEL= "Treatment duration, Weeks";
RUN;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Annotation 2020-08-29 050758.png" style="width: 740px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48779i2B2A6683BDDB6D4D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Annotation 2020-08-29 050758.png" alt="Annotation 2020-08-29 050758.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;DIV id="tinyMceEditorRafiRahi_4" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for looking into this and I look forward to your kind guidance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Aug 2020 04:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680179#M20428</guid>
      <dc:creator>RafiRahi</dc:creator>
      <dc:date>2020-08-29T04:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SGPLOT - How to keep the order of events in stack bar as they are in dataset</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680184#M20429</link>
      <description>&lt;P&gt;Can you post some sample of your data?&lt;/P&gt;</description>
      <pubDate>Sat, 29 Aug 2020 06:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680184#M20429</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-08-29T06:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SGPLOT - How to keep the order of events in stack bar as they are in dataset</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680190#M20430</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you can&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;achieve your result by switching to &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://blogs.sas.com/content/graphicallyspeaking/2014/06/16/grouped-timeline/" target="_self"&gt;a HIGHLOW plot&lt;/A&gt;&lt;SPAN style="font-family: inherit;"&gt;. These are used a lot in clinical graphs. Two examples to get you started are&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2014/06/22/swimmer-plot/" target="_self"&gt;Swimmer plots&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2013/01/30/ae-timeline-by-name/" target="_self"&gt;Adverse events plots&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here's an example with fake data to get you started:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Aug 2020 10:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680190#M20430</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-08-29T10:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SGPLOT - How to keep the order of events in stack bar as they are in dataset</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680225#M20431</link>
      <description>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).</description>
      <pubDate>Sat, 29 Aug 2020 17:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680225#M20431</guid>
      <dc:creator>RafiRahi</dc:creator>
      <dc:date>2020-08-29T17:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SGPLOT - How to keep the order of events in stack bar as they are in dataset</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680226#M20432</link>
      <description>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!</description>
      <pubDate>Sat, 29 Aug 2020 17:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/PROC-SGPLOT-How-to-keep-the-order-of-events-in-stack-bar-as-they/m-p/680226#M20432</guid>
      <dc:creator>RafiRahi</dc:creator>
      <dc:date>2020-08-29T17:08:25Z</dc:date>
    </item>
  </channel>
</rss>

