<?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: Two IF statements within a BY statement in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Two-IF-statements-within-a-BY-statement/m-p/853391#M37545</link>
    <description>&lt;P&gt;The IF statements are not "within" BY statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first IF statement is taking advantage of the fact that when using a BY statement SAS will create flag variables that will indicate if the current observation is the first or last in the current BY group.&amp;nbsp; So it resets the counter variable the data step is creating to zero when a new group starts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your guess on the second IF statement is going to be better than mine.&amp;nbsp; Especially since it is referencing a macro variable, SUP_MAX,&amp;nbsp; that you have not defined anywhere.&amp;nbsp; (Programming hint: Do not use "magic" macro variables in macro code.&amp;nbsp; That is a macro variable that is suddenly used by the macro but has never been defined by the macro and is not an input parameter of the macro.&amp;nbsp; At the very least add a comment at the top of the macro stating that the macro will be using this externally defined macro variable.)&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2023 05:29:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-12T05:29:57Z</dc:date>
    <item>
      <title>Two IF statements within a BY statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Two-IF-statements-within-a-BY-statement/m-p/853388#M37544</link>
      <description>&lt;P&gt;How do two or more if statements work within a By statement. I was looking at the macro suppress in this link:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sgf/2016/04/13/automatic-data-suppression-in-sas-reports/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sgf/2016/04/13/automatic-data-suppression-in-sas-reports/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;(and also below) and I found that once the code in blue ran, the macro ran the code in green. It almost seemed like a loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;&lt;SPAN&gt;%macro&lt;/SPAN&gt; suppress&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;dsname&lt;/SPAN&gt;=,supclass=&lt;SPAN&gt;)&lt;/SPAN&gt;;
&amp;nbsp;
   &lt;SPAN&gt;proc sort&lt;/SPAN&gt; &lt;SPAN&gt;data&lt;/SPAN&gt;=&amp;amp;&lt;SPAN&gt;dsname&lt;/SPAN&gt;;
      &lt;SPAN&gt;by&lt;/SPAN&gt; &lt;SPAN&gt;&amp;amp;supclass&lt;/SPAN&gt; count;
   &lt;SPAN&gt;run&lt;/SPAN&gt;;
&amp;nbsp;
   &lt;SPAN&gt;%let&lt;/SPAN&gt; sup_flag = &lt;SPAN&gt;0&lt;/SPAN&gt;;
   &lt;SPAN&gt;data&lt;/SPAN&gt; &amp;amp;&lt;SPAN&gt;dsname&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;drop&lt;/SPAN&gt;=_supnum_&lt;SPAN&gt;)&lt;/SPAN&gt;;
      &lt;SPAN&gt;set&lt;/SPAN&gt; &amp;amp;&lt;SPAN&gt;dsname&lt;/SPAN&gt;;
      &lt;SPAN&gt;by&lt;/SPAN&gt; &lt;SPAN&gt;&amp;amp;supclass&lt;/SPAN&gt; count;
      &lt;SPAN&gt;if&lt;/SPAN&gt; first.&lt;SPAN&gt;&amp;amp;supclass&lt;/SPAN&gt; &lt;SPAN&gt;then&lt;/SPAN&gt; _supnum_ = &lt;SPAN&gt;0&lt;/SPAN&gt;;
   &lt;FONT color="#339966"&gt;   &lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt; le count le &lt;SPAN&gt;&amp;amp;sup_max&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt; &lt;SPAN&gt;or&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt;_supnum_ eq &lt;SPAN&gt;1&lt;/SPAN&gt; &lt;SPAN&gt;and&lt;/SPAN&gt; count ne .S&lt;SPAN&gt;)&lt;/SPAN&gt; &lt;SPAN&gt;then&lt;/SPAN&gt;
      &lt;SPAN&gt;do&lt;/SPAN&gt;;
         count = .S;
         &lt;SPAN&gt;call&lt;/SPAN&gt; symput&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'sup_flag'&lt;/SPAN&gt;,&lt;SPAN&gt;'1'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;;
      &lt;SPAN&gt;end&lt;/SPAN&gt;;&lt;/FONT&gt;
&lt;FONT color="#0000FF"&gt;      &lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt;count eq .S&lt;SPAN&gt;)&lt;/SPAN&gt; &lt;SPAN&gt;then&lt;/SPAN&gt; _supnum_ + &lt;SPAN&gt;1&lt;/SPAN&gt;;&lt;/FONT&gt;
   &lt;SPAN&gt;run&lt;/SPAN&gt;;
&amp;nbsp;
&lt;SPAN&gt;%mend&lt;/SPAN&gt; suppress;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 04:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Two-IF-statements-within-a-BY-statement/m-p/853388#M37544</guid>
      <dc:creator>kk89</dc:creator>
      <dc:date>2023-01-12T04:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Two IF statements within a BY statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Two-IF-statements-within-a-BY-statement/m-p/853391#M37545</link>
      <description>&lt;P&gt;The IF statements are not "within" BY statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first IF statement is taking advantage of the fact that when using a BY statement SAS will create flag variables that will indicate if the current observation is the first or last in the current BY group.&amp;nbsp; So it resets the counter variable the data step is creating to zero when a new group starts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your guess on the second IF statement is going to be better than mine.&amp;nbsp; Especially since it is referencing a macro variable, SUP_MAX,&amp;nbsp; that you have not defined anywhere.&amp;nbsp; (Programming hint: Do not use "magic" macro variables in macro code.&amp;nbsp; That is a macro variable that is suddenly used by the macro but has never been defined by the macro and is not an input parameter of the macro.&amp;nbsp; At the very least add a comment at the top of the macro stating that the macro will be using this externally defined macro variable.)&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 05:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Two-IF-statements-within-a-BY-statement/m-p/853391#M37545</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-12T05:29:57Z</dc:date>
    </item>
  </channel>
</rss>

