<?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  and or conditions in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878658#M347169</link>
    <description>&lt;P&gt;You need to use %SYSEVALF to perform non-integer arithmetic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simplified Example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let col=833.49;

%macro test;
%if %sysevalf(&amp;amp;COL&amp;gt;1000) %then %do;
%put "doesn't exist";
%end;
%else %do;
proc print data=sashelp.class;
run;
%end;
%mend;
%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what you see in the log from the above code&lt;/P&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;
&lt;PRE&gt;MPRINT(TEST):   proc print data=sashelp.class;
MPRINT(TEST):   run;
&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;
&lt;P&gt;but if you remove the %SYSEVALF, this is what you get&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%if &amp;amp;COL&amp;gt;1000 %then %do;
%put "doesn't exist";
%end;
%else %do;
proc print data=sashelp.class;
run;
%end;
%mend;
%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;MLOGIC(TEST):  %IF condition &amp;amp;COL&amp;gt;1000 is TRUE
MLOGIC(TEST):  %PUT "doesn't exist"
"doesn't exist"
&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, 01 Jun 2023 12:50:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-06-01T12:50:31Z</dc:date>
    <item>
      <title>If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878640#M347158</link>
      <description>&lt;P&gt;I am trying to get the output if&amp;nbsp; if conditions are met then output something or print table but Conditions doesn't work. Even below condition is true or not true it always giving true output. Tried with different true or false conditions but it prints always true condition which is not right. Am I missing some logic. See the attached file for data.&lt;/P&gt;
&lt;PRE&gt;proc import datafile="/test/test.xls "
out=test dbms=xls replace;
run;


proc sql noprint;
	select Despatches into :COL from test where inflight_type = 'Collect' ;
quit;

proc sql noprint;
	select a2_Sales into :COL2 from test where inflight_type = 'Collect' ;
quit;

proc sql noprint;
	select Despatches into :POST from test where inflight_type = 'Post';
quit;

proc sql noprint;
	select a2_Sales into :POST2 from test where inflight_type = 'Post' ;
quit;

proc sql noprint;
	select Despatches into :DEPOT from test where inflight_type = 'Depot'; 
quit;	

proc sql noprint;
	select a2_Sales into :DEPOT2 from test where inflight_type = 'Depot' ;
quit;

%put &amp;amp;COL &amp;amp;COL2 &amp;amp;POST &amp;amp;POST2 &amp;amp;DEPOT &amp;amp;DEPOT2;

%macro test;

%if (&amp;amp;COL&amp;gt;1000 or &amp;amp;COL2&amp;gt;5 or &amp;amp;POST&amp;gt;0 or &amp;amp;POST2&amp;gt;0 or &amp;amp;depot&amp;gt;1000 or &amp;amp;depot2&amp;gt;1 ) %then %do;
%put "doesn't exist";
%end;
%else %do;
proc print data=sashelp.class;
run;
%end;
%mend;
%test;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 12:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878640#M347158</guid>
      <dc:creator>sathya66</dc:creator>
      <dc:date>2023-06-01T12:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878642#M347159</link>
      <description>&lt;P&gt;&amp;amp;depot resolves to 130, which is larger than 1. Did you mean to use &amp;amp;depot&lt;U&gt;2&lt;/U&gt; in your last sub-condition?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 11:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878642#M347159</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-01T11:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878643#M347160</link>
      <description>&lt;P&gt;Most of us refuse to download Excel files. So we cannot see your data. If you want to provide data for us, the only acceptable way is via working SAS data step code (see &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;here&lt;/A&gt; for examples and instructions).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show us the output from this command:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;COL &amp;amp;COL2 &amp;amp;POST &amp;amp;POST2 &amp;amp;DEPOT &amp;amp;DEPOT2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 11:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878643#M347160</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-01T11:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878652#M347165</link>
      <description>Sorry yes, it is  &amp;amp;depot2</description>
      <pubDate>Thu, 01 Jun 2023 12:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878652#M347165</guid>
      <dc:creator>sathya66</dc:creator>
      <dc:date>2023-06-01T12:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878653#M347166</link>
      <description>%put COl=&amp;amp;COL ;&lt;BR /&gt;COl= 833.49&lt;BR /&gt;%put Col2=&amp;amp;COL2;&lt;BR /&gt;Col2=0.68&lt;BR /&gt;%put POST=&amp;amp;POST ;&lt;BR /&gt;POST=0&lt;BR /&gt;%put POST2=&amp;amp;POST2 ;&lt;BR /&gt;POST2=0&lt;BR /&gt;%put DEPOT=&amp;amp;DEPOT ;&lt;BR /&gt;DEPOT= 130&lt;BR /&gt;%put DEPOT2=&amp;amp;DEPOT2;&lt;BR /&gt;DEPOT2=0.13</description>
      <pubDate>Thu, 01 Jun 2023 12:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878653#M347166</guid>
      <dc:creator>sathya66</dc:creator>
      <dc:date>2023-06-01T12:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878654#M347167</link>
      <description>&lt;P&gt;So none of your conditions is met, and sashelp.class is printed.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 12:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878654#M347167</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-01T12:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878656#M347168</link>
      <description>&lt;P&gt;My output is different.&lt;BR /&gt;See my output below it is printing "doesn't exist"&lt;/P&gt;
&lt;PRE&gt;28         %put &amp;amp;COL &amp;amp;COL2 &amp;amp;POST &amp;amp;POST2 &amp;amp;DEPOT &amp;amp;DEPOT2;
833.49            0.68               0               0             130            0.13
29         %macro test;
30         
31         %if (&amp;amp;COL&amp;gt;1000 or &amp;amp;COL2&amp;gt;5 or &amp;amp;POST&amp;gt;0 or &amp;amp;POST2&amp;gt;0 or &amp;amp;depot&amp;gt;1000 or &amp;amp;depot2&amp;gt;1 ) %then %do;
32         %put "doesn't exist";
33         %end;
34         %else %do;
35         proc print data=sashelp.class;
36         run;
37         %end;
38         %mend;
39         %test;
"doesn't exist"&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Jun 2023 12:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878656#M347168</guid>
      <dc:creator>sathya66</dc:creator>
      <dc:date>2023-06-01T12:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878658#M347169</link>
      <description>&lt;P&gt;You need to use %SYSEVALF to perform non-integer arithmetic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simplified Example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let col=833.49;

%macro test;
%if %sysevalf(&amp;amp;COL&amp;gt;1000) %then %do;
%put "doesn't exist";
%end;
%else %do;
proc print data=sashelp.class;
run;
%end;
%mend;
%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what you see in the log from the above code&lt;/P&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;
&lt;PRE&gt;MPRINT(TEST):   proc print data=sashelp.class;
MPRINT(TEST):   run;
&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;
&lt;P&gt;but if you remove the %SYSEVALF, this is what you get&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%if &amp;amp;COL&amp;gt;1000 %then %do;
%put "doesn't exist";
%end;
%else %do;
proc print data=sashelp.class;
run;
%end;
%mend;
%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;MLOGIC(TEST):  %IF condition &amp;amp;COL&amp;gt;1000 is TRUE
MLOGIC(TEST):  %PUT "doesn't exist"
"doesn't exist"
&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, 01 Jun 2023 12:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878658#M347169</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-01T12:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: If  and or conditions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878663#M347170</link>
      <description>&lt;P&gt;Just to add a bit to Paige's correct answer... The %IF statement uses the %EVAL function to evaluate expressions.&amp;nbsp; %EVAL can evaluate both numeric expressions and character expressions.&amp;nbsp; But there is no way for you to tell %EVAL to do a numeric comparison or a character comparison.&amp;nbsp; So %EVAL needs to look at the expression, and decide whether to do a numeric comparison or character comparison.&amp;nbsp; It has simple rules to make this decision, basically, if the operands are all numbers, do a numeric comparison, else do a character comparison.&amp;nbsp; Unfortunately, %EVAL does not know that a decimal point can be part of a number. So if you do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %eval(2 &amp;gt; 10.0) ;&amp;nbsp;%*True-&amp;nbsp;character&amp;nbsp;comparison;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you get 1 (true), because it's doing a character (alphabetical) comparison.&amp;nbsp; It's the equivalent of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if "2"&amp;gt;"10.0" then put "2 is greater than 10.0" ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;%SYSEVALF also has to decide whether to do a numeric or character expression, but it knows that a decimal point can be part of a number.&amp;nbsp; So&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysevalf(2&amp;gt;10.0) ;&amp;nbsp;%*False&amp;nbsp;-&amp;nbsp;numeric&amp;nbsp;comparison;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;returns false because it does a numeric comparison.&amp;nbsp; If you add an extra dot to 10.0, %sysevalf sees that 10.0. is not a number, and changes to a character comparison&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysevalf(2&amp;gt;10.0.) ; %*True- character comparison;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 13:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-and-or-conditions-in-SAS/m-p/878663#M347170</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-06-01T13:29:15Z</dc:date>
    </item>
  </channel>
</rss>

