<?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: why it is going in else loop even if condition is not satisfied? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512911#M138178</link>
    <description>&lt;P&gt;Thanks. Will keep in mind regarding the code for future.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Nov 2018 11:43:13 GMT</pubDate>
    <dc:creator>khushi</dc:creator>
    <dc:date>2018-11-14T11:43:13Z</dc:date>
    <item>
      <title>why it is going in else loop even if condition is not satisfied?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512905#M138175</link>
      <description>&lt;P&gt;My code is as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;%let &lt;FONT face="Calibri"&gt;&amp;amp;_DOMAIN &lt;/FONT&gt;= 'S' ;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;DATA _NULL_;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp; IF &amp;amp;_DOMAIN = 'S' THEN DO;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; = "&lt;FONT face="Calibri"&gt;CAPP_1Q18_ACAS_Detail_R00_20171101_Primary&lt;/FONT&gt;";&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;%LET _DTLTRAD1&amp;nbsp; = "&lt;FONT face="Calibri"&gt;CAPP_1Q18_ACAS_Detail_R00_20171101_Secondary&lt;/FONT&gt;";&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp; END;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;ELSE IF &amp;amp;_DOMAIN = 'A' THEN DO;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF &amp;amp;_state IN ('CO','CT','DE','MA','ME','MN','NH','OR','UT','VT','VA') THEN DO;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; =&amp;nbsp; "&amp;amp;ST1._APCD_Y&amp;amp;YR.M&amp;amp;MN._eRCE_STND_DET_PRIME.txt" ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LET _DTLTRAD1&amp;nbsp; = "&amp;amp;ST1._APCD_Y&amp;amp;YR.M&amp;amp;MN._eRCE_STND_DET.txt" ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE IF &amp;amp;_state IN ('AR','KS','WA') THEN DO;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; =&amp;nbsp; "&amp;amp;ST1._APCD_Y&amp;amp;YR.Q&amp;amp;QT._eRCE_STND_DET_PRIME.txt" ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LET _DTLTRAD1&amp;nbsp; = "&amp;amp;ST1._APCD_Y&amp;amp;YR.Q&amp;amp;QT._eRCE_STND_DET.txt" ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&amp;nbsp; END;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp; END;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp; PUT &amp;amp;_DTLTRAD;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp; PUT &amp;amp;_DTLTRAD1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp; RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result of this is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;AR_APCD_Y17Q01_eRCE_STND_DET_PRIME.txt&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;AR_APCD_Y17Q01_eRCE_STND_DET.txt&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where it should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;CAPP_1Q18_ACAS_Detail_R00_20171101_Primary&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;CAPP_1Q18_ACAS_Detail_R00_20171101_Secondary&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help? I cant understand why it is going in second loop.&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 11:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512905#M138175</guid>
      <dc:creator>khushi</dc:creator>
      <dc:date>2018-11-14T11:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: why it is going in else loop even if condition is not satisfied?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512908#M138176</link>
      <description>&lt;P&gt;Classical misunderstanding of macro and macro timing. The macro&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;PRE&lt;/STRONG&gt;&lt;/U&gt;processor (note the emphasis) does its work&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; the data step is compiled and executed, so all the %let's are worked through, with the results of the final ones sticking. Since no code is created, the do/end blocks of the data step remain empty and do nothing.&lt;U&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a data step to create macro variables, use call symput() or call symputx().&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 11:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512908#M138176</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-14T11:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: why it is going in else loop even if condition is not satisfied?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512910#M138177</link>
      <description>&lt;P&gt;There are several issues in your.&amp;nbsp; First off, and most important is to write code which people can read.&amp;nbsp; This means not shouting code in upper case, using the code window - its the {i} above post area, finishing statments, and not mixing up macro and datastep code.&lt;/P&gt;
&lt;P&gt;First issue, you are mixing macro and datastep.&amp;nbsp; Macro is nothing more than a text find/replace system which is done&amp;nbsp;&lt;STRONG&gt;before&lt;/STRONG&gt; any code is executed.&amp;nbsp; Therfore you cannot set %let conditionally from datastep as they have already resolved by then.&amp;nbsp; So when the datastep - where the if construct is - is run, all those %let statements have resolved and are no longer part of the code.&amp;nbsp; What you perhaps want is call symput:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  select("&amp;amp;_domain.");
    when("S") do;
      call symputx("_dtltrad","capp_1q18_acas_detail_r00_20171101_primary");
      call symputx("_dtltrad1","capp_1q18_acas_detail_r00_20171101_secondary");
      end;
    when("A") do;
       ...
      end;
  end;
run;

%put &amp;amp;_dtltrad.;
%put &amp;amp;_dtltrad1.;&lt;/PRE&gt;
&lt;P&gt;Note how I enclose macro variables in double quotes when I use in the datastep - this is key for them to be resolved.&amp;nbsp; And it is good practice to always end a macro variable with a . as well.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 11:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512910#M138177</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-14T11:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: why it is going in else loop even if condition is not satisfied?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512911#M138178</link>
      <description>&lt;P&gt;Thanks. Will keep in mind regarding the code for future.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 11:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-it-is-going-in-else-loop-even-if-condition-is-not-satisfied/m-p/512911#M138178</guid>
      <dc:creator>khushi</dc:creator>
      <dc:date>2018-11-14T11:43:13Z</dc:date>
    </item>
  </channel>
</rss>

