<?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: If - then - else is fulfilling both criterias in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619876#M182082</link>
    <description>You're mixing macro and data step logic and I have no idea where &amp;amp;nrows comes from. Maybe explain what you're trying to do and we can offer suggestions on how to accomplish that.</description>
    <pubDate>Fri, 24 Jan 2020 17:11:54 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-01-24T17:11:54Z</dc:date>
    <item>
      <title>If - then - else is fulfilling both criterias</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619873#M182080</link>
      <description>&lt;P&gt;I have the following code with an if-then-else statement.&amp;nbsp; Both the If and the Else are running.&amp;nbsp; The value of &amp;amp;nrows being input to this dataset = 1 which meets the IF condition.&amp;nbsp; I know the Else is running because after the code executes "cancel" = the value from the Else do statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _NULL_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if 0 then set specs_step2 nobs=n;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;if &amp;amp;nrows &amp;gt; 0 then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;%put NOTE: Program terminated because there are missing IRNs in the data.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;%put See the Results or Output window for the cases where these are needed.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;%put Putstate3 = There are &amp;amp;nrows. IRNs to update.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;%let cancel = cancel;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;else do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;%put NOTE: Continue processing. All IRNs are provided in the dataset.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;%let cancel = This is the else condition;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;stop;&lt;BR /&gt;run;&lt;BR /&gt;%put Cancel = &amp;amp;cancel. ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 17:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619873#M182080</guid>
      <dc:creator>StaceyB</dc:creator>
      <dc:date>2020-01-24T17:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: If - then - else is fulfilling both criterias</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619875#M182081</link>
      <description>&lt;P&gt;Macro language statements such as %PUT and %LET are never part of a DATA step.&amp;nbsp; They cannot be controlled using DATA step IF THEN statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A DATA step can use PUT statements (not %PUT) to write messages, and can use CALL SYMPUTX to assign values to macro variables.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 17:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619875#M182081</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-24T17:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: If - then - else is fulfilling both criterias</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619876#M182082</link>
      <description>You're mixing macro and data step logic and I have no idea where &amp;amp;nrows comes from. Maybe explain what you're trying to do and we can offer suggestions on how to accomplish that.</description>
      <pubDate>Fri, 24 Jan 2020 17:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619876#M182082</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-24T17:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: If - then - else is fulfilling both criterias</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619878#M182084</link>
      <description>&lt;P&gt;I did have the idea that I was mixing&amp;nbsp; up the macros with the data step.&amp;nbsp; I've been changing it around in all different ways.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will update to put instead of %put and will change the let statement to symputx.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 17:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619878#M182084</guid>
      <dc:creator>StaceyB</dc:creator>
      <dc:date>2020-01-24T17:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: If - then - else is fulfilling both criterias</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619886#M182085</link>
      <description>&lt;P&gt;Okay, it's still not quite working.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a previous step in the code I'm setting the value of the &amp;amp;nrows.&amp;nbsp; Now I'd like to set the value of &amp;amp;cancel to either a blank or to the value of cancel and write to the log the corresponding put statements in the code above.&amp;nbsp; In the following statements I end them with:&lt;/P&gt;
&lt;P&gt;run &amp;amp;cancel;&amp;nbsp; By doing this the remaining code doesn't run based on the value that was in &amp;amp;nrows at the point I'm placing the code in this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does that help a little bit?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 17:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619886#M182085</guid>
      <dc:creator>StaceyB</dc:creator>
      <dc:date>2020-01-24T17:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: If - then - else is fulfilling both criterias</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619889#M182086</link>
      <description>&lt;P&gt;Do you just wan this then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;        %if &amp;amp;nrows &amp;gt; 0 %then %do;
               %put NOTE: Program terminated because there are missing IRNs in the data.;
               %put See the Results or Output window for the cases where these are needed.;
               %put Putstate3 = There are &amp;amp;nrows. IRNs to update.;
               %let cancel = cancel;
          %end;
          %else %do;
               %put NOTE: Continue processing. All IRNs are provided in the dataset.;
               %let cancel = This is the else condition;
            %end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39915"&gt;@StaceyB&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Okay, it's still not quite working.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a previous step in the code I'm setting the value of the &amp;amp;nrows.&amp;nbsp; Now I'd like to set the value of &amp;amp;cancel to either a blank or to the value of cancel and write to the log the corresponding put statements in the code above.&amp;nbsp; In the following statements I end them with:&lt;/P&gt;
&lt;P&gt;run &amp;amp;cancel;&amp;nbsp; By doing this the remaining code doesn't run based on the value that was in &amp;amp;nrows at the point I'm placing the code in this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does that help a little bit?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 17:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619889#M182086</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-24T17:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: If - then - else is fulfilling both criterias</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619891#M182087</link>
      <description>&lt;P&gt;Perfect.&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 17:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619891#M182087</guid>
      <dc:creator>StaceyB</dc:creator>
      <dc:date>2020-01-24T17:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: If - then - else is fulfilling both criterias</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619892#M182088</link>
      <description>&lt;P&gt;So you have NROWS macro variable and you want to create CANCEL macro variable.&lt;/P&gt;
&lt;P&gt;You can do that with macro code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;nrows &amp;gt;&amp;nbsp;0&amp;nbsp;%then %do;
  %let cancel=cancel;
%end;
%else %do;
  %let cancel=;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are not running this inside a macro (or are using an old version of SAS that does not support %IF in open code) you could use a data step instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cancel=;
data _null_;
  if &amp;amp;nrows &amp;gt;&amp;nbsp;0&amp;nbsp;then call symputx('cancel','cancel');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Our use %sysfunc() to call the IFC() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cancel=%sysfunc(ifc(&amp;amp;nobs &amp;gt; 0,cancel,));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jan 2020 17:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-is-fulfilling-both-criterias/m-p/619892#M182088</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-24T17:44:48Z</dc:date>
    </item>
  </channel>
</rss>

