<?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: treat last.observation of a group different in array (SAS 9.3 or 9.4) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272699#M269519</link>
    <description>&lt;P&gt;A simple change to the structure of your data will make your life a lot easier:&lt;/P&gt;
&lt;P&gt;IDGEM &amp;nbsp; &amp;nbsp; &amp;nbsp; JAHR &amp;nbsp; &amp;nbsp;HALV_MONTH &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;0100100 &amp;nbsp; &amp;nbsp; 1996 &amp;nbsp; &amp;nbsp; 01JAN &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;0100100 &amp;nbsp; &amp;nbsp; 1996 &amp;nbsp; &amp;nbsp; 02JAN &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can simply group by whichever grouping you need.&lt;/P&gt;</description>
    <pubDate>Tue, 24 May 2016 12:21:49 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-05-24T12:21:49Z</dc:date>
    <item>
      <title>treat last.observation of a group different in array (SAS 9.3 or 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272675#M269517</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;i have a dataset where the observations are grouped by an ID (idgem) and each grout has observations for several years (jahr) ba halv month steps (jan1 - dec2) looks like this:&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3309i00D89CBBC0EA83AB/image-size/original?v=v2&amp;amp;px=-1" alt="bsp.GIF" title="bsp.GIF" border="0" /&gt;&lt;/P&gt;&lt;P&gt;i wrote an array to find the local maximum (precipitaion data) in comparing each variable with the following and the previous variable.&lt;/P&gt;&lt;P&gt;the dec2 value is compared with the jan1 value of the following (by copying the column) year and jan1 is compared with dec2 of the previous year (by the lag function).&amp;nbsp;&lt;/P&gt;&lt;P&gt;now i have the problem with the first an the last year within a group (idgem).&lt;/P&gt;&lt;P&gt;how do i tell SAS to compare dec2 of the last year just to dec1 of the same year and ignore jan1 of the following year.&lt;/P&gt;&lt;P&gt;i tried with an if last.jahr then option, but it doesn't work. my code looks like this (the corresponding part is marked green at the end of it):&lt;/P&gt;&lt;PRE&gt;data test4;
 set mani;
   array local [24]; /* kreiert eine neue Datenmatrix mit den Überschriften local1-local24, ohne Werte, Variablen wird ein Indice zugewiesen in [] */
   do _n_ = 1 to 24;
   local[_n_] = "" ;
 end;
  array maxi [24] jan1 jan2 feb1 feb2 mar1 mar2 apr1 apr2 may1 may2 jun1 jun2 /* definiert quasi die Variablen des 'Quell-arrays' hier: maxi mit den Quelldaten */
                  jul1 jul2 aug1 aug2 sep1 sep2 oct1 oct2 nov1 nov2 dec1 dec2;
  do _n_ = 2 to 23;
    if (maxi [_n_-1] &amp;lt; maxi [_n_]) and (maxi [_n_]&amp;gt; maxi [_n_+1]) then local [_n_] = maxi [_n_];
    if maxi [_n_] = maxi [_n_-1] then local [_n_] = maxi [_n_];
    if maxi [_n_] = maxi [_n_+1] then local [_n_] = maxi [_n_];
   end;
  do _n_ = 1; /* lag Funktion vergleicht mit dem Wert dec2 der vorhergehenden Observation */
    if (maxi [_n_] &amp;gt; maxi [_n_+1]) and (maxi [_n_] &amp;gt; lag(dec2)) then local [_n_] = maxi [_n_];
    if (maxi [_n_] = maxi [_n_+1]) and (maxi [_n_] = lag(dec2)) then local [_n_] = maxi [_n_];
   end;
  do _n_= 24;
    if (maxi [_n_] &amp;gt; maxi [_n_-1]) and (maxi [_n_] &amp;gt; jan1follow) then local [_n_] = maxi [_n_];
    if (maxi [_n_] = maxi [_n_-1]) and (maxi [_n_] = jan1follow) then local [_n_] = maxi [_n_]; 
   end;
  &lt;FONT color="#339966"&gt;if (last.jahr) then do _n_ = 24;
    if (maxi [_n_] &amp;gt; maxi [_n_-1]) then local [_n_] = maxi [_n_];
    if (maxi [_n_] = maxi [_n_-1]) then local [_n_] = maxi [_n_]; 
  end;
  if first.jahr then do _n_ = 1;
    if (maxi [_n_] &amp;gt; maxi [_n_+1]) then local [_n_] = maxi [_n_];
    if (maxi [_n_] = maxi [_n_+1]) then local [_n_] = maxi [_n_];
  end;&lt;/FONT&gt;
run; &lt;/PRE&gt;&lt;P&gt;there is no error message but also no difference in the results!&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;&lt;P&gt;greets,&lt;/P&gt;&lt;P&gt;Sandra&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2016 10:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272675#M269517</guid>
      <dc:creator>Sandra_L</dc:creator>
      <dc:date>2016-05-24T10:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: treat last.observation of a group different in array (SAS 9.3 or 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272693#M269518</link>
      <description>&lt;P&gt;o.k. i think i have to tell SAS to treat last.idgem different (not last.jahr)! but still it makes no difference&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2016 11:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272693#M269518</guid>
      <dc:creator>Sandra_L</dc:creator>
      <dc:date>2016-05-24T11:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: treat last.observation of a group different in array (SAS 9.3 or 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272699#M269519</link>
      <description>&lt;P&gt;A simple change to the structure of your data will make your life a lot easier:&lt;/P&gt;
&lt;P&gt;IDGEM &amp;nbsp; &amp;nbsp; &amp;nbsp; JAHR &amp;nbsp; &amp;nbsp;HALV_MONTH &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;0100100 &amp;nbsp; &amp;nbsp; 1996 &amp;nbsp; &amp;nbsp; 01JAN &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;0100100 &amp;nbsp; &amp;nbsp; 1996 &amp;nbsp; &amp;nbsp; 02JAN &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can simply group by whichever grouping you need.&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2016 12:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272699#M269519</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-24T12:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: treat last.observation of a group different in array (SAS 9.3 or 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272718#M269520</link>
      <description>&lt;P&gt;Hallo Sandra,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your programming logic, using first.&lt;EM&gt;idgem&lt;/EM&gt; and last.&lt;EM&gt;idgem&lt;/EM&gt; of course, looks correct to me (except that I'm not sure why in a situation like m4 = m5 &amp;lt; m6, value m5 should be&amp;nbsp;regarded as a local &lt;EM&gt;maximum&lt;/EM&gt;), but you have to insert a BY statement after the SET statement to make first./last.idgem work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by idgem;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whether the newly added (green) blocks of code then have an impact on the results, still depends on the data (in dataset MANI):&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;If the new IF conditions (regarding maxi[...]) are not met, the assignment statements for local[_n_] will not be executed. But in this case the corresponding assignment statements in the previous blocks of code have not been executed either, because the IF conditions there are stronger. (local[_n_] will be missing in this case.)&lt;/LI&gt;
&lt;LI&gt;If (either of) the new IF conditions &lt;EM&gt;are&lt;/EM&gt; met, the pertinent assignment statement will be executed. But in this case the corresponding &lt;EM&gt;identical&lt;/EM&gt; assignment statement in the previous blocks of code might have been executed already: in the case that the additional condition (involving lag(dec2) or jan1follow, respectively) was met.&lt;/LI&gt;
&lt;LI&gt;So, the only situation where the added code can influence the results is that&amp;nbsp;&lt;SPAN&gt;(either of) the new IF conditions are met, whilst the corresponding additional condition was not satisfied.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 24 May 2016 13:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272718#M269520</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-24T13:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: treat last.observation of a group different in array (SAS 9.3 or 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272741#M269521</link>
      <description>Hi Reinhard,&lt;BR /&gt;thak you for the lonx exlplication!&lt;BR /&gt;It was just the missing by statement, now it works nicely!&lt;BR /&gt;The local maximum for m5 in the situation m5&amp;lt;m6 is because m5 is the last value of the time series and m6 already belongs to a different station, so to make sure even if m5&amp;lt;m6 but m5&amp;gt;m4, that it declares m5 as max.&lt;BR /&gt;Thanks a lot,&lt;BR /&gt;Sandra</description>
      <pubDate>Tue, 24 May 2016 14:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/treat-last-observation-of-a-group-different-in-array-SAS-9-3-or/m-p/272741#M269521</guid>
      <dc:creator>Sandra_L</dc:creator>
      <dc:date>2016-05-24T14:04:13Z</dc:date>
    </item>
  </channel>
</rss>

