<?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: Make plot change color after date(s) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686158#M208162</link>
    <description>&lt;P&gt;First issue is that your last data step uses a variable that doesn't exist:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data have;
set have;
If .&amp;lt;dx1 ge age_measurement  /* the previously defined varaible is age_measure*/
then dummy_var = 2;
else 
If .&amp;lt;dx1 LT age_measurement then dummy_var=1;
else dummy_var=.;
run;
&lt;/LI-CODE&gt;
&lt;P&gt;If you fix the variable name and run&lt;/P&gt;
&lt;PRE&gt;data have;
set have;
If .&amp;lt;dx1 ge age_measure
then dummy_var = 2;
else 
If .&amp;lt;dx1 LT age_measure then dummy_var=1;
else dummy_var=.;
run;&lt;/PRE&gt;
&lt;P&gt;At least with the example data you only have 1 non-missing value for your dummy_var which isn't going to provide much for a colorresponse. And the colorresponse option means that group will be ignored.&lt;/P&gt;
&lt;P&gt;You do know that " .&amp;lt;dx1" in the code is returning values of 0 and 1 don't you? So everything is "less than" your shown age_measure (or age_measurement after get the names straight) in the example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus you have two variables in the series statement that do not exist in the example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide an image similar to what you expect to see?&lt;/P&gt;</description>
    <pubDate>Wed, 23 Sep 2020 17:48:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-09-23T17:48:39Z</dc:date>
    <item>
      <title>Make plot change color after date(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686132#M208152</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;I am working with some longitudinal data, where I am making a spaghetti-plot for each patient.&amp;nbsp;&lt;BR /&gt;I need to "mark" the occurrence of some dates in the plot, and I have thought about doing that with a dummy-variable and use the colourresponse option, but I can't get it to do it right.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So, below is a test-dataset containing patientid, visit_date, measurement, age at measure, date of diagnosis 1 (dx1), date of diagnosis 2 (dx2). The desired output is a spaghetti-plot with patient id as group, and where the color changes when the visitdate passes the diagnosis date.&amp;nbsp;&lt;BR /&gt;In the code below I have only made the dummy variable contain diagnosis 1, it would be a great help to show me, how to incorporate the date of diagnosis 2 also.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data patients;
input patientid $ (dx1 dx2) (:yymmdd8.);
format dx1 dx2 yymmdd10.;
datalines;
1 20180101 20180101
2 20170205 .
3 20170221 20170225
4 20180101 20180202
5 . 20180503
;

data visits;
input patientid $ visit_date :yymmdd8. measure age_measure;
format visit_date yymmdd10.;
datalines;
1  20180101  3.4   10
1  20180505  2.3   15
2  20170210  7.3   20
2  20170217  7.2   25
2  20170220  7.1   30
3  20170221  5.4   35
4  20180202  3.4   23
4  20180204  3.2   25
5  20180504  5.6   30
5  20180505  5.0   32
;
data have;
merge
  patients
  visits
;
by patientid;
run;

/* The plot */

data have;
set have;
If .&amp;lt;dx1 ge age_measurement
then dummy_var = 2;
else 
If .&amp;lt;dx1 LT age_measurement then dummy_var=1;
else dummy_var=.;
run;


proc sgplot data=have noborder subpixel;
    series x=age_measurement y=measurement / group=patientid colorresponse=dummy_var colormodel=(red gold green) lineattrs=(thickness=2);
    xaxis display=(noline noticks nolabel) grid;
    yaxis display=(noline noticks nolabel) grid;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 16:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686132#M208152</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2020-09-23T16:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Make plot change color after date(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686158#M208162</link>
      <description>&lt;P&gt;First issue is that your last data step uses a variable that doesn't exist:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data have;
set have;
If .&amp;lt;dx1 ge age_measurement  /* the previously defined varaible is age_measure*/
then dummy_var = 2;
else 
If .&amp;lt;dx1 LT age_measurement then dummy_var=1;
else dummy_var=.;
run;
&lt;/LI-CODE&gt;
&lt;P&gt;If you fix the variable name and run&lt;/P&gt;
&lt;PRE&gt;data have;
set have;
If .&amp;lt;dx1 ge age_measure
then dummy_var = 2;
else 
If .&amp;lt;dx1 LT age_measure then dummy_var=1;
else dummy_var=.;
run;&lt;/PRE&gt;
&lt;P&gt;At least with the example data you only have 1 non-missing value for your dummy_var which isn't going to provide much for a colorresponse. And the colorresponse option means that group will be ignored.&lt;/P&gt;
&lt;P&gt;You do know that " .&amp;lt;dx1" in the code is returning values of 0 and 1 don't you? So everything is "less than" your shown age_measure (or age_measurement after get the names straight) in the example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus you have two variables in the series statement that do not exist in the example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide an image similar to what you expect to see?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 17:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686158#M208162</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-23T17:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Make plot change color after date(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686165#M208166</link>
      <description>&lt;P&gt;Dear Ballardw,&amp;nbsp;&lt;/P&gt;&lt;P&gt;something like this were red = before dx1, gold = after dx1 (before dx2), green = after dx2&amp;nbsp;&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="Slide1.jpeg" style="width: 720px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49721iA5DA381C79D636C3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Slide1.jpeg" alt="Slide1.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 18:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686165#M208166</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2020-09-23T18:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Make plot change color after date(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686181#M208175</link>
      <description>&lt;P&gt;Your patientid 1 has dx1 and dx2 the same date. So what should happen?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure that the x axis shouldn't be a date axis?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is "age_measure" supposed to mean "age at measurement"? If so then you need to convert the dates of dx1 and dx2 to age_measure equivalents (somehow) and compare them directly to the age_measure values.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686181#M208175</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-23T19:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Make plot change color after date(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686288#M208210</link>
      <description>&lt;P&gt;Thanks for pointing that mistake out! Patients can't have dx1 and 2 on the same date, patient 2 has dx2 20181001.&lt;BR /&gt;&lt;BR /&gt;Hmm yes, if it is possible. Age_measure is correctly age at measurement.&lt;BR /&gt;okay so, if I convert the dates of dx1 and dx2 to age_measure equivalents (I can do that).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What will my proc SGPLOT code then look like ?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 06:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-plot-change-color-after-date-s/m-p/686288#M208210</guid>
      <dc:creator>lone0708</dc:creator>
      <dc:date>2020-09-25T06:48:45Z</dc:date>
    </item>
  </channel>
</rss>

