<?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: LOOK BACK - PEEK AHEAD in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247771#M46462</link>
    <description>What if missing street is first or last, no previous or no next respectively.  What if there are 2 or more missing in a row?</description>
    <pubDate>Wed, 03 Feb 2016 15:28:15 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-02-03T15:28:15Z</dc:date>
    <item>
      <title>LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247762#M46459</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to solve how to fill a char var with a string based on the previous and following values as a conditional.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; STREET &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CITY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; STATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ZIP &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;YEAR &amp;nbsp; &amp;nbsp; IX&lt;BR /&gt;1001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;999 MAIN ST &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TUPELO &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99999 &amp;nbsp; &amp;nbsp;1992&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;1001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TUPELO &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99999 &amp;nbsp; &amp;nbsp;1994&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;1001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;999 MAIN ST &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TUPELO &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99999 &amp;nbsp; &amp;nbsp;1996&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like the STREET for the second row to be "999 MAIN ST" because 92', 94', and 96' IX=1 and Row 1 STREET is the same as Row 2 STREET.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; STREET &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CITY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; STATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ZIP &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;YEAR &amp;nbsp; &amp;nbsp; IX&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;999 MAIN ST &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TUPELO &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99999 &amp;nbsp; &amp;nbsp;199&lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;999 MAIN ST&lt;/STRONG&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TUPELO &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99999 &amp;nbsp; &amp;nbsp;199&lt;/SPAN&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;999 MAIN ST &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TUPELO &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99999 &amp;nbsp; &amp;nbsp;199&lt;/SPAN&gt;&lt;SPAN&gt;6&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As always thank you for your help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2016 14:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247762#M46459</guid>
      <dc:creator>UMAnalyst</dc:creator>
      <dc:date>2016-02-03T14:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247765#M46460</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data set_new (drop=lid lstreet nid nstreet);
merge
  set_old
  set_old (firstobs=2 keep=id street rename=(id=nid street=nstreet))
;
lid = lag(id);
lstreet = lag(street);
if street = . and lid = id and nid = id and lstreet = nstreet then street = lstreet;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2016 15:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247765#M46460</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-02-03T15:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247766#M46461</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So get a list of values where street is not null, then merge that back on. &amp;nbsp;The coalsce takes the first non-missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select A.ID,
           coalesce(A.STREET,B.STREET) as STREET,
           A.CITY,
           A.STATE,
           A.ZIP,
           A.YEAR,
           A.IX
  from   HAVE A
  left join (select distinct ID,IX,STREET from HAVE where STREET is not null) B
  on     A.ID=B.ID
  and   A.IX=B.IX;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2016 15:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247766#M46461</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-03T15:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247771#M46462</link>
      <description>What if missing street is first or last, no previous or no next respectively.  What if there are 2 or more missing in a row?</description>
      <pubDate>Wed, 03 Feb 2016 15:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247771#M46462</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-02-03T15:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247776#M46463</link>
      <description>&lt;P&gt;And what if CITY, STATE or&amp;nbsp;ZIP differ&amp;nbsp;between&amp;nbsp;the previous and next observation?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2016 15:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247776#M46463</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-03T15:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247779#M46465</link>
      <description>Yes, good point. If those other vars i.e., CITY, STATE, and ZIP do not match, then the street-fill should not occur.</description>
      <pubDate>Wed, 03 Feb 2016 15:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247779#M46465</guid>
      <dc:creator>UMAnalyst</dc:creator>
      <dc:date>2016-02-03T15:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247783#M46466</link>
      <description>&lt;P&gt;Update per updated code:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select A.ID,
           coalesce(A.STREET,B.STREET) as STREET,
           A.CITY,
           A.STATE,
           A.ZIP,
           A.YEAR,
           A.IX
  from   HAVE A
  left join (select distinct ID,IX,CITY,STATE,ZIP,STREET from HAVE where STREET is not null) B
  on     A.ID=B.ID
  and   A.IX=B.IX
  and   A.CITY=B.CITY
  and   A.STATE=B.STATE
  and   A.ZIP=B.ZIP;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2016 16:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/247783#M46466</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-03T16:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/248338#M46650</link>
      <description>&lt;P&gt;Can this merge execute properly without a BY-statement? Also, is it possible to merge on the same input data twice i.e., "set_old"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2016 16:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/248338#M46650</guid>
      <dc:creator>UMAnalyst</dc:creator>
      <dc:date>2016-02-05T16:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: LOOK BACK - PEEK AHEAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/250027#M47112</link>
      <description>&lt;P&gt;A MERGE without a BY merges the records in their physical order in the datasets.&lt;/P&gt;
&lt;P&gt;And yes, the same dataset can be used more than once in a SET or MERGE statement in a DATA step. Care needs to be taken with the variables by properly KEEPing and RENAMEing them, so you don't get unexpected overwrites.&lt;/P&gt;
&lt;P&gt;What I do is I use the LAG() function to get previous values, while reading the same dataset starting at obs=2 gives me the "peek ahead".&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 07:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOK-BACK-PEEK-AHEAD/m-p/250027#M47112</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-02-15T07:30:05Z</dc:date>
    </item>
  </channel>
</rss>

