<?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 Compare values in an array and replace it if it's before the one previous. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-values-in-an-array-and-replace-it-if-it-s-before-the-one/m-p/735127#M228998</link>
    <description>&lt;P&gt;Hi i have an array called disch (*) disch1-disch9.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a second array with empty values called dis_new(*) disch_new1-disch_new9.&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="lei_0-1618775487894.png" style="width: 833px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58300i478ABC37F0200328/image-dimensions/833x25?v=v2" width="833" height="25" role="button" title="lei_0-1618775487894.png" alt="lei_0-1618775487894.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;disch_new takes on the value of disch if its value is after the disch prior. However, if the disch value is before, then i want disch_new to take on the prior.&amp;nbsp;Therefore, dischnew1-6 are the same as disch1-6. However, dischnew7-dischnew9 all become 26June18:10:00:00.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not having any luck with the way I have it set up. If anyone can help that will be great.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current code is this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ARRAY DIS(*) DISCH1 - DISCH&amp;amp;IDY;&lt;BR /&gt;ARRAY DIS_NEW (*) DISCH_NEW1 - DISCH_NEW&amp;amp;IDY.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DIS_NEW[1]=DIS[1];&lt;BR /&gt;DIS_NEW[2]=DIS[2];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;/* If discharge date ends prior to previous discharge*/&lt;/P&gt;
&lt;P&gt;DO I=2 TO DIM(DIS_NEW);&lt;BR /&gt;IF DIS_NEW[I]&amp;lt;DIS[I-1] THEN DIS_NEW[I]=DIS[I-1];&lt;BR /&gt;ELSe DIS_NEW[I]=DIS[I];&lt;BR /&gt;END;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Apr 2021 20:01:38 GMT</pubDate>
    <dc:creator>lei</dc:creator>
    <dc:date>2021-04-18T20:01:38Z</dc:date>
    <item>
      <title>Compare values in an array and replace it if it's before the one previous.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-values-in-an-array-and-replace-it-if-it-s-before-the-one/m-p/735127#M228998</link>
      <description>&lt;P&gt;Hi i have an array called disch (*) disch1-disch9.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a second array with empty values called dis_new(*) disch_new1-disch_new9.&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="lei_0-1618775487894.png" style="width: 833px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58300i478ABC37F0200328/image-dimensions/833x25?v=v2" width="833" height="25" role="button" title="lei_0-1618775487894.png" alt="lei_0-1618775487894.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;disch_new takes on the value of disch if its value is after the disch prior. However, if the disch value is before, then i want disch_new to take on the prior.&amp;nbsp;Therefore, dischnew1-6 are the same as disch1-6. However, dischnew7-dischnew9 all become 26June18:10:00:00.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not having any luck with the way I have it set up. If anyone can help that will be great.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current code is this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ARRAY DIS(*) DISCH1 - DISCH&amp;amp;IDY;&lt;BR /&gt;ARRAY DIS_NEW (*) DISCH_NEW1 - DISCH_NEW&amp;amp;IDY.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DIS_NEW[1]=DIS[1];&lt;BR /&gt;DIS_NEW[2]=DIS[2];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;/* If discharge date ends prior to previous discharge*/&lt;/P&gt;
&lt;P&gt;DO I=2 TO DIM(DIS_NEW);&lt;BR /&gt;IF DIS_NEW[I]&amp;lt;DIS[I-1] THEN DIS_NEW[I]=DIS[I-1];&lt;BR /&gt;ELSe DIS_NEW[I]=DIS[I];&lt;BR /&gt;END;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Apr 2021 20:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-values-in-an-array-and-replace-it-if-it-s-before-the-one/m-p/735127#M228998</guid>
      <dc:creator>lei</dc:creator>
      <dc:date>2021-04-18T20:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in an array and replace it if it's before the one previous.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-values-in-an-array-and-replace-it-if-it-s-before-the-one/m-p/735164#M229020</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do I = 1 to DIM(DIS_NEW);
  DIS_NEW[I] = max( DIS_NEW[I-1], DIS[I] );
end;&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;</description>
      <pubDate>Mon, 19 Apr 2021 05:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-values-in-an-array-and-replace-it-if-it-s-before-the-one/m-p/735164#M229020</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-19T05:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values in an array and replace it if it's before the one previous.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-values-in-an-array-and-replace-it-if-it-s-before-the-one/m-p/735174#M229025</link>
      <description>&lt;P&gt;I believe for a&amp;nbsp;DISCH_NEW&amp;lt;n&amp;gt; variable to never have a value lower than&amp;nbsp;DISCH_NEW&amp;lt;n-1&amp;gt; the code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;posted needs a tweak. Below should do the job.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let IDY=11;

data have;
  input DISCH1 - DISCH&amp;amp;IDY;
  datalines;
1 2 1 1 3 4 2 2 2 4 5
;

data want;
  set have;
  ARRAY DIS(*) DISCH1 - DISCH&amp;amp;IDY;
  ARRAY DIS_NEW (*) DISCH_NEW1 - DISCH_NEW&amp;amp;IDY.;
  DIS_NEW[1]=DIS[1];

  /* If discharge date ends prior to previous discharge*/
  DO I=2 TO DIM(DIS_NEW);
    IF DIS[I]&amp;lt;DIS_NEW[I-1] THEN
      DIS_NEW[I]=DIS_NEW[I-1];
    ELSe DIS_NEW[I]=DIS[I];
  END;
run;

proc print data=want;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 06:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-values-in-an-array-and-replace-it-if-it-s-before-the-one/m-p/735174#M229025</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-19T06:48:19Z</dc:date>
    </item>
  </channel>
</rss>

