<?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: Help!  How can I find out how to &amp;quot;capture&amp;quot; the 2nd obs. within each group?! in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-How-can-I-find-out-how-to-quot-capture-quot-the-2nd-obs/m-p/50837#M13882</link>
    <description>If you combine first. and retain I think can get what you want:&lt;BR /&gt;
&lt;BR /&gt;
data x;&lt;BR /&gt;
set y;&lt;BR /&gt;
by z;&lt;BR /&gt;
retain nGrp;&lt;BR /&gt;
if first.z then nGrp = 1;&lt;BR /&gt;
else if nGrp = 2 then output;&lt;BR /&gt;
nGrp+1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Am I on the right track?&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
    <pubDate>Wed, 01 Oct 2008 10:13:50 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2008-10-01T10:13:50Z</dc:date>
    <item>
      <title>Help!  How can I find out how to "capture" the 2nd obs. within each group?!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-How-can-I-find-out-how-to-quot-capture-quot-the-2nd-obs/m-p/50836#M13881</link>
      <description>Ok, so here's my problem...have spent the past 2 hours trying to find the answer, to no avail.  I need to find a way to capture/select the SECOND occurrence of a variable (just call it "flag") returning a value of 1...WITHIN each age group.  The data has already been sorted by age group (and then by "flag", which is dichotomous, having a value of 1 or 0).  I know how to get the first and last value by using FIRST.group and LAST.group, but I can't figure out how to select the second (or third, tenth, etc., you get the idea).  Remember that this is not just the second observation of the data set - this is the second occurrence of flag=1 WITHIN each age group.  HELP HELP HELP ASAP!!!  And thanks a million!</description>
      <pubDate>Wed, 01 Oct 2008 07:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-How-can-I-find-out-how-to-quot-capture-quot-the-2nd-obs/m-p/50836#M13881</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-01T07:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help!  How can I find out how to "capture" the 2nd obs. within each group?!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-How-can-I-find-out-how-to-quot-capture-quot-the-2nd-obs/m-p/50837#M13882</link>
      <description>If you combine first. and retain I think can get what you want:&lt;BR /&gt;
&lt;BR /&gt;
data x;&lt;BR /&gt;
set y;&lt;BR /&gt;
by z;&lt;BR /&gt;
retain nGrp;&lt;BR /&gt;
if first.z then nGrp = 1;&lt;BR /&gt;
else if nGrp = 2 then output;&lt;BR /&gt;
nGrp+1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Am I on the right track?&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Wed, 01 Oct 2008 10:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-How-can-I-find-out-how-to-quot-capture-quot-the-2nd-obs/m-p/50837#M13882</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-10-01T10:13:50Z</dc:date>
    </item>
  </channel>
</rss>

