<?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 first.variable in a group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/first-variable-in-a-group/m-p/745028#M233491</link>
    <description>&lt;P&gt;Could you please explain below code&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;data xyz;&lt;BR /&gt;input x $;&lt;BR /&gt;cards;&lt;BR /&gt;AA&lt;BR /&gt;AA&lt;BR /&gt;AA&lt;BR /&gt;BB&lt;BR /&gt;BB&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data A;&lt;BR /&gt;set xyz;&lt;BR /&gt;by x;&lt;BR /&gt;if first.x then &lt;BR /&gt;N+1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;output :-&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Obs x N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 AA 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 AA 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 AA 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;4 BB 2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 BB&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data B;&lt;BR /&gt;set xyz;&lt;BR /&gt;by x;&lt;BR /&gt;if first.x then N=1;&lt;BR /&gt;else N+1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;output for B is&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Obs x N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 AA 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 AA&amp;nbsp; 2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 AA&amp;nbsp; 3&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;4 BB&amp;nbsp; 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 BB 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how dateset&amp;nbsp;B is created its the incrementing the value based of the occurrence&amp;nbsp;of by group x but not sure how dataset A is being created .&lt;/P&gt;
&lt;P&gt;Please explain.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Jun 2021 19:31:59 GMT</pubDate>
    <dc:creator>Aexor</dc:creator>
    <dc:date>2021-06-01T19:31:59Z</dc:date>
    <item>
      <title>first.variable in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-variable-in-a-group/m-p/745028#M233491</link>
      <description>&lt;P&gt;Could you please explain below code&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;data xyz;&lt;BR /&gt;input x $;&lt;BR /&gt;cards;&lt;BR /&gt;AA&lt;BR /&gt;AA&lt;BR /&gt;AA&lt;BR /&gt;BB&lt;BR /&gt;BB&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data A;&lt;BR /&gt;set xyz;&lt;BR /&gt;by x;&lt;BR /&gt;if first.x then &lt;BR /&gt;N+1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;output :-&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Obs x N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 AA 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 AA 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 AA 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;4 BB 2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 BB&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data B;&lt;BR /&gt;set xyz;&lt;BR /&gt;by x;&lt;BR /&gt;if first.x then N=1;&lt;BR /&gt;else N+1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;output for B is&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Obs x N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 AA 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 AA&amp;nbsp; 2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 AA&amp;nbsp; 3&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;4 BB&amp;nbsp; 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 BB 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how dateset&amp;nbsp;B is created its the incrementing the value based of the occurrence&amp;nbsp;of by group x but not sure how dataset A is being created .&lt;/P&gt;
&lt;P&gt;Please explain.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 19:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-variable-in-a-group/m-p/745028#M233491</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-06-01T19:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: first.variable in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-variable-in-a-group/m-p/745031#M233493</link>
      <description>&lt;P&gt;The SUM statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;N + 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;implies an automatic RETAIN of the variable.&lt;/P&gt;
&lt;P&gt;In dataset A, the increment happens only when a new group starts; when this happens the first time (and N is still missing), N is set to 1 (like it happens with missing values in a SUM function).&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 19:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-variable-in-a-group/m-p/745031#M233493</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-01T19:42:47Z</dc:date>
    </item>
  </channel>
</rss>

