<?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: by statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802477#M315920</link>
    <description>&lt;P&gt;You can move the subsetting IF up one line, to avoid calculating MOB_VAL_P in ever data step iteration, when it is really needed only once. I also streamlined the first condition, so that the unnecessary increment in the first observation of a group is avoided.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;Portfolio_VAL2 (keep=MOB_VAL_P MOB );
set &amp;amp;Portofo._VAL;
by MOB;
if first.MOB
then CNT = 1;
else CNT + 1;
if last.MOB;
MOB_VAL_P = cnt / &amp;amp;total_val.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Mar 2022 12:31:09 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-03-16T12:31:09Z</dc:date>
    <item>
      <title>by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802427#M315891</link>
      <description>&lt;PRE&gt;DATA &amp;amp;Portfolio_VAL2(Keep=MOB_VAL_P MOB );
set &amp;amp;Portofo._VAL;
by MOB;
if first.MOB then CNT=0;
CNT+1;
MOB_VAL_P=cnt/&amp;amp;total_val,;
if last.MOB;
run;&lt;/PRE&gt;
&lt;P&gt;hi can you let me know what does the statement "by MOB;" doing on the third row? what does it mean when it comes after set statement?&amp;nbsp; also should the "if last.MOB" statement put higher up? or it does not matter where it is positioned?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 07:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802427#M315891</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-16T07:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802428#M315892</link>
      <description>&lt;P&gt;It initiates BY group processing, a prt of it is creation the autmatic.first and .last variables.&lt;/P&gt;
&lt;P&gt;It's a whole concept, you could read about in the documentqation.&lt;/P&gt;
&lt;P&gt;I think you need to keep .last where it is, since it stops processing of subsequent statements for that record (if it doesn't meet the criteria).&lt;/P&gt;
&lt;P&gt;The easiest way to find out how things work, try to run the code yourself, examine the results, and if needed use the data step debugger.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 07:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802428#M315892</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-03-16T07:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802443#M315897</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.mob;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;probably belongs where it is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can easily see what effect it has, by deleting it, or moving it, and looking at the data set, and see what happens. As stated by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt; you should really read the documentation on these extremely important FIRST. and LAST. variables.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 10:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802443#M315897</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-16T10:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802477#M315920</link>
      <description>&lt;P&gt;You can move the subsetting IF up one line, to avoid calculating MOB_VAL_P in ever data step iteration, when it is really needed only once. I also streamlined the first condition, so that the unnecessary increment in the first observation of a group is avoided.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;Portfolio_VAL2 (keep=MOB_VAL_P MOB );
set &amp;amp;Portofo._VAL;
by MOB;
if first.MOB
then CNT = 1;
else CNT + 1;
if last.MOB;
MOB_VAL_P = cnt / &amp;amp;total_val.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Mar 2022 12:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/by-statement/m-p/802477#M315920</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-16T12:31:09Z</dc:date>
    </item>
  </channel>
</rss>

