<?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 do statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-statements/m-p/907758#M358327</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I just want to ask if someone can look at the code I wrote if it's correct and if there's a way to shorten it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How can we know if it is correct? You know if it is correct, because it either does what you want, or it does not do what you want.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As far as shortening it, let's look at this part:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc = . then Home_Branch = nearest_location;
if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc = . then Home_Branch = nearest_location;
if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc ne . then Home_Branch = nearest_location;
if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc ne . then Home_Branch = nearest_location;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In all four of the statements above, you set Home_Brach to be equal to nearest_location. Then you don't need four statements. In fact, it seems that no matter what the values of PDL_Loc and Service_Loc are, you set Home_Branch to be equal to nearest_location.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So the four statements can really be reduced to one statement&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) then Home_Branch = nearest_location;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I didn't look carefully at the rest of your code.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Dec 2023 14:34:35 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-12-13T14:34:35Z</dc:date>
    <item>
      <title>if then do statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-statements/m-p/907753#M358323</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope everybody is doing well.&amp;nbsp; I just want to ask if someone can look at the code I wrote if it's correct and if there's a way to shorten it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;below is the code:&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data Cust_Loc; set Cust_wLoans2 (drop=Dist);&lt;/DIV&gt;
&lt;DIV&gt;if Store_Is_Open = 0 then do;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc = . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc = . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc ne . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc ne . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_loc not in (&amp;amp;closed_loc) and LOc_Inst_loc not in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc = . then Home_Branch = LOC_Inst_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_loc not in (&amp;amp;closed_loc) and LOc_Inst_loc not in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc = . then Home_Branch = LOC_Inst_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_loc not in (&amp;amp;closed_loc) and LOc_Inst_loc not in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc ne . then Home_Branch = LOC_Inst_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_loc not in (&amp;amp;closed_loc) and LOc_Inst_loc not in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc ne . then Home_Branch = LOC_Inst_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_Loc = . and (PDL_Loc in (&amp;amp;closed_loc) or PDL_Loc in (&amp;amp;web_loc)) and Service_Loc = . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_Loc = . and (PDL_Loc in (&amp;amp;closed_loc) or PDL_Loc in (&amp;amp;web_loc)) and Service_Loc ne . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_Loc = . and (PDL_Loc not in (&amp;amp;closed_loc) and PDL_Loc not in (&amp;amp;web_loc)) and Service_Loc = . then Home_Branch = PDL_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_Loc = . and (PDL_Loc not in (&amp;amp;closed_loc) and PDL_Loc not in (&amp;amp;web_loc)) and Service_Loc ne . then Home_Branch = PDL_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_Loc = . and PDL_Loc = . and Service_Loc in (&amp;amp;closed_loc) then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_Loc = . and PDL_Loc = . and Service_Loc not in (&amp;amp;closed_loc) then Home_Branch = Service_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;end;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;if Store_Is_Open = 1 then do;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc not in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc = . then Home_Branch = LOC_Inst_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc not in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc = . then Home_Branch = LOC_Inst_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc not in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc ne . then Home_Branch = LOC_Inst_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_loc = . and (PDL_Loc ne . and PDL_loc not in (&amp;amp;web_loc)) and Service_loc = . then Home_Branch = PDL_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_loc = . and (PDL_Loc ne . and PDL_loc not in (&amp;amp;web_loc)) and Service_loc ne . then Home_Branch = PDL_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_loc = . and PDL_Loc = . and (Service_loc ne . and Service_loc not in (&amp;amp;web_loc)) then Home_Branch = Service_loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc = . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc = . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc ne . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_loc = . and (PDL_Loc ne . and PDL_loc in (&amp;amp;web_loc)) and Service_loc = . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_loc = . and (PDL_Loc ne . and PDL_loc in (&amp;amp;web_loc)) and Service_loc ne . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc not in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc ne . then Home_Branch = LOC_Inst_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc ne . then Home_Branch = Service_Loc;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_Loc = . and PDL_Loc = . and Service_Loc = . then Home_Branch = nearest_location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc in (&amp;amp;closed_loc)) and PDL_Loc = . and Service_Loc = . then Home_Branch = Nearest_Location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc in (&amp;amp;closed_loc)) and PDL_Loc ne . and Service_Loc = . then Home_Branch = Nearest_Location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc in (&amp;amp;closed_loc)) and PDL_Loc ne . and Service_Loc ne . then Home_Branch = Nearest_Location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (LOC_Inst_Loc ne . and LOC_Inst_Loc in (&amp;amp;closed_loc)) and PDL_Loc = . and Service_Loc ne . then Home_Branch = Nearest_Location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_loc = . and (PDL_Loc ne . and PDL_loc in (&amp;amp;closed_loc)) and Service_loc = . then Home_Branch = Nearest_Location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_loc = . and (PDL_Loc ne . and PDL_loc in (&amp;amp;closed_loc)) and Service_loc ne . then Home_Branch = Nearest_Location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if LOC_Inst_Loc in (&amp;amp;web_loc) and PDL_Loc = . and Service_Loc in (&amp;amp;closed_loc) then Home_Branch = Nearest_Location;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;end;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;format Home_Branch best.;&lt;/DIV&gt;
&lt;DIV&gt;;run;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 14:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-statements/m-p/907753#M358323</guid>
      <dc:creator>Eugenio211</dc:creator>
      <dc:date>2023-12-13T14:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: if then do statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-statements/m-p/907758#M358327</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I just want to ask if someone can look at the code I wrote if it's correct and if there's a way to shorten it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How can we know if it is correct? You know if it is correct, because it either does what you want, or it does not do what you want.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As far as shortening it, let's look at this part:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc = . then Home_Branch = nearest_location;
if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc = . then Home_Branch = nearest_location;
if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc ne . and Service_Loc ne . then Home_Branch = nearest_location;
if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) and PDL_Loc = . and Service_Loc ne . then Home_Branch = nearest_location;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In all four of the statements above, you set Home_Brach to be equal to nearest_location. Then you don't need four statements. In fact, it seems that no matter what the values of PDL_Loc and Service_Loc are, you set Home_Branch to be equal to nearest_location.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So the four statements can really be reduced to one statement&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (LOC_Inst_loc in (&amp;amp;closed_loc) or LOc_Inst_loc in (&amp;amp;web_loc)) then Home_Branch = nearest_location;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I didn't look carefully at the rest of your code.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 14:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-statements/m-p/907758#M358327</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-12-13T14:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: if then do statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-statements/m-p/907759#M358328</link>
      <description>&lt;P&gt;What is it supposed to be doing?&lt;/P&gt;
&lt;P&gt;You shouldn't code a boolean expression like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A or B and C&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What does that mean?&amp;nbsp; Which operator should SAS execute first?&lt;/P&gt;
&lt;P&gt;Add parentheses so you are certain it will do what you want because these two possibilities will yield different results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(A or B) and C
A or (B and C)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it does not make much sense to code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if A and B and C then X=1;
if A and B and not C then X=1;
if A and not B and C then X=1;
if A and not B and not C then X=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since all combinations of B and C and set the value of X to the same thing each time you simplify to&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if A then X=1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2023 14:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-statements/m-p/907759#M358328</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-13T14:36:52Z</dc:date>
    </item>
  </channel>
</rss>

