<?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 Plotting Multiple Time-Series While Shading in PROC GPLOT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554890#M154402</link>
    <description>&lt;P&gt;I have two time-series variables with similar scales and two indicator variables. I need to plot the two time-series using the first vertical axis and shade the plot using the two indicators. The following code creates a sample data set.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _;
do t=1 to 100;
w=ifn(t=1,rannor(1),0.9*w+sqrt(1-0.9**2)*rannor(1));
x=ifn(t=1,rannor(1),0.9*x+sqrt(1-0.9**2)*rannor(1));
y=ifn(-1&amp;lt;x&amp;lt;=0,1,0);
z=ifn(x&amp;lt;=-1,1,0);
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The following is the resulting plot of x (blue) and w (red) from PROC GPLOT.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29108iB8C1E8E72889C4FC/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I need to shade this plot using the other variables y and z, so I can use PLOT1, PLOT2, and OVERLAY. The following is the code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;symbol1 i=join ci=blue;
symbol2 i=join ci=red;
symbol3 i=join ci=white;
pattern1 v=solid c=ltgray;
pattern2 v=solid c=gray;
pattern3 v=solid c=white;

proc gplot;
	plot1 x*t;
	plot2 (y z)*t/areas=3 overlay;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And the following is the outcome with x (blue), y (ltgray), and z (gray)—w is excluded.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29109i83D5586EC6ED07E6/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I thought that just adding w in PLOT1 works, but it failed with the following log.&lt;/P&gt;&lt;PRE&gt;2    symbol1 i=join ci=blue;
3    symbol2 i=join ci=red;
4    symbol3 i=join ci=white;
5    pattern1 v=solid c=ltgray;
6    pattern2 v=solid c=gray;
7    pattern3 v=solid c=white;
8
9    proc gplot;
10       plot1 (x w)*t;
11       plot2 (y z)*t/areas=3 overlay;
12   run;

ERROR: Number of plot requests on PLOT and PLOT2 statements must match.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE GPLOT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;&lt;P&gt;How can I shade a plot with multiple time-series variables by multiple indicator variables? Thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Apr 2019 01:26:56 GMT</pubDate>
    <dc:creator>Junyong</dc:creator>
    <dc:date>2019-04-30T01:26:56Z</dc:date>
    <item>
      <title>Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554890#M154402</link>
      <description>&lt;P&gt;I have two time-series variables with similar scales and two indicator variables. I need to plot the two time-series using the first vertical axis and shade the plot using the two indicators. The following code creates a sample data set.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _;
do t=1 to 100;
w=ifn(t=1,rannor(1),0.9*w+sqrt(1-0.9**2)*rannor(1));
x=ifn(t=1,rannor(1),0.9*x+sqrt(1-0.9**2)*rannor(1));
y=ifn(-1&amp;lt;x&amp;lt;=0,1,0);
z=ifn(x&amp;lt;=-1,1,0);
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The following is the resulting plot of x (blue) and w (red) from PROC GPLOT.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29108iB8C1E8E72889C4FC/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I need to shade this plot using the other variables y and z, so I can use PLOT1, PLOT2, and OVERLAY. The following is the code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;symbol1 i=join ci=blue;
symbol2 i=join ci=red;
symbol3 i=join ci=white;
pattern1 v=solid c=ltgray;
pattern2 v=solid c=gray;
pattern3 v=solid c=white;

proc gplot;
	plot1 x*t;
	plot2 (y z)*t/areas=3 overlay;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And the following is the outcome with x (blue), y (ltgray), and z (gray)—w is excluded.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29109i83D5586EC6ED07E6/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I thought that just adding w in PLOT1 works, but it failed with the following log.&lt;/P&gt;&lt;PRE&gt;2    symbol1 i=join ci=blue;
3    symbol2 i=join ci=red;
4    symbol3 i=join ci=white;
5    pattern1 v=solid c=ltgray;
6    pattern2 v=solid c=gray;
7    pattern3 v=solid c=white;
8
9    proc gplot;
10       plot1 (x w)*t;
11       plot2 (y z)*t/areas=3 overlay;
12   run;

ERROR: Number of plot requests on PLOT and PLOT2 statements must match.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE GPLOT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;&lt;P&gt;How can I shade a plot with multiple time-series variables by multiple indicator variables? Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 01:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554890#M154402</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-04-30T01:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554899#M154408</link>
      <description>Are you required to use GPLOT? SGPLOT is pretty clear.</description>
      <pubDate>Tue, 30 Apr 2019 02:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554899#M154408</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-30T02:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554918#M154420</link>
      <description>No, but I strongly prefer GPLOT to SGPLOT as have used it for years and do not know the details of SGPLOT.</description>
      <pubDate>Tue, 30 Apr 2019 04:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554918#M154420</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-04-30T04:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554922#M154422</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   proc gplot;
       plot1 (x w)*t/overlay;
       plot2 (y z)*t/areas=3 overlay;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 05:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554922#M154422</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-30T05:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554926#M154423</link>
      <description>&lt;P&gt;Much appreciate. When there are N time-series and M indicators, it seems N+M SYMBOLs and M+1 PATTERNs are needed. Here I attach the working example.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;resetline;
dm"log;clear;output;clear;graph;end;odsresult;clear;";
option nodate nonumber nolabel ls=128 ps=max;
proc datasets kill nolist;
run;
data _;
do t=1 to 100;
x=ifn(t=1,rannor(1),0.9*x+sqrt(1-0.9**2)*rannor(1));
y=ifn(t=1,rannor(1),0.9*y+sqrt(1-0.9**2)*rannor(1));
z=ifn(-0.5&amp;lt;=x&amp;lt;0,1,0);
w=ifn(-1&amp;lt;=x&amp;lt;-0.5,1,0);
v=ifn(x&amp;lt;-1,1,0);
u+rannor(1);
output;
end;
run;
data _;
set _;
if abs(z-lag(z))=1 or abs(w-lag(w))=1 or abs(v-lag(v))=1 then output;
output;
run;
data _;
set _;
if abs(z-lag(z))=1 then z=1-z;
if abs(w-lag(w))=1 then w=1-w;
if abs(v-lag(v))=1 then v=1-v;
run;
symbol1 i=join ci=blue;
symbol2 i=join ci=red;
symbol3 i=join ci=green;
symbol4 i=join ci=white;
symbol5 i=join ci=white;
symbol6 i=join ci=white;
pattern1 v=solid c=ltgray;
pattern2 v=solid c=gray;
pattern3 v=solid c=dagray;
pattern4 v=solid c=white;
proc gplot;
plot1 (x y u)*t/overlay;
plot2 (z w v)*t/areas=4 overlay;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29111i425AE808D15B7E2B/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 05:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/554926#M154423</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-04-30T05:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555148#M154483</link>
      <description>&lt;P&gt;Since we cannot actually duplicate your data set as the example relies heavily on random values, can you describe the rules in terms of eth variables as to how the width and color of those vertical bars is determined?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no clue as to why a light gray bar starts or ends on any specific position.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 17:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555148#M154483</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-30T17:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555155#M154486</link>
      <description>I think the first DATA step generates the same data set as RANNOR uses 1 as the seed. X (blue) follows a standard AR(1) process with ρ=0.9, Z (ltgray) is 1 if X∈[-0.5,0), W (gray) is 1 if X∈[-1,-0.5), and V (dagray) is 1 if X∈(-∞,-1), correspondingly.</description>
      <pubDate>Tue, 30 Apr 2019 17:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555155#M154486</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-04-30T17:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555235#M154501</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; it seems N+M SYMBOLs and M+1 PATTERNs are needed&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just N+1 symbols afaik, since the area plots are plots too. This yields&amp;nbsp;the same plot:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;goptions reset=all ;
symbol1 i=join ci=blue;
symbol2 i=join ci=red;
symbol3 i=join ci=green;
symbol4 i=join;
pattern1 v=solid c=ltgray;
pattern2 v=solid c=gray;
pattern3 v=solid c=dagray;
proc gplot;
  plot1 (X Y U) * T /overlay; 
  plot2 (Z W V) * T /areas=3 overlay;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 22:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555235#M154501</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-30T22:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555537#M154610</link>
      <description>&lt;P&gt;It seems they are necessary as the colors are changed. The following is the outcome from your code. Not the same.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="0.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29155iD898073D24C3BDAC/image-size/large?v=v2&amp;amp;px=999" role="button" title="0.png" alt="0.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 06:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555537#M154610</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-05-02T06:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting Multiple Time-Series While Shading in PROC GPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555809#M154731</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;It seems they are necessary as the colors are changed. The following is the outcome from your code. Not the same.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;That's odd. My code generates a white background. Anyways that's a detail for the task at hand. Glad you got the result you wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _;
do t=1 to 100;
x=ifn(t=1,rannor(1),0.9*x+sqrt(1-0.9**2)*rannor(1));
y=ifn(t=1,rannor(1),0.9*y+sqrt(1-0.9**2)*rannor(1));
z=ifn(-0.5&amp;lt;=x&amp;lt;0,1,0);
w=ifn(-1&amp;lt;=x&amp;lt;-0.5,1,0);
v=ifn(x&amp;lt;-1,1,0);
u+rannor(1);
if abs(z-lag(z))=1 or abs(w-lag(w))=1 or abs(v-lag(v))=1 then output;
output;
end;
run;
data _;
set _;
if abs(z-lag(z))=1 then z=1-z;
if abs(w-lag(w))=1 then w=1-w;
if abs(v-lag(v))=1 then v=1-v;
run;
goptions reset=all dev=png;
symbol1 i=join ci=blue;
symbol2 i=join ci=red;
symbol3 i=join ci=green;
symbol4 i=join;
pattern1 v=solid c=ltgray;
pattern2 v=solid c=gray;
pattern3 v=solid c=dagray;
proc gplot;
  plot1 (X Y U) * T /overlay; 
  plot2 (Z W V) * T /areas=3 overlay;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29177i79F6859A6597B762/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 23:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Plotting-Multiple-Time-Series-While-Shading-in-PROC-GPLOT/m-p/555809#M154731</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-02T23:39:05Z</dc:date>
    </item>
  </channel>
</rss>

