<?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: Index of Do loop not recognized in IF statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258613#M268993</link>
    <description>&lt;P&gt;I suppose this might happen if your second data set contains 0 observations.&amp;nbsp; But you can make it easy to diagnose.&amp;nbsp; Just add this before you run:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options symbolgen;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you will be able to see the values you are working with for your macro variables.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Mar 2016 19:57:33 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-03-23T19:57:33Z</dc:date>
    <item>
      <title>Index of Do loop not recognized in IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258599#M268991</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been trying to figure out what I am doing wrong, but can't, so here I am posting the problem hoping someone can provide me some solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Problem:&lt;/P&gt;&lt;P&gt;I have a IF statement within Do loop within DATA step. The IF statement evaluates by comparing Do loop index with a macro variable. Somehow the two values in comparison are not properly evaluated and thus, the codes always return ELSE values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro TEMP();

%do i = 1 %to &amp;amp;Sample.;
    %do j = 1 %to &amp;amp;DD.;

         /*some codes*/    

        %let dsid = %sysfunc(open(TEMP_0));
        %let CNT_0 = %sysfunc(attrn(&amp;amp;dsid,NOBS));
        %let CC = %sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;
        %let dsid = %sysfunc(open(TEMP_00));
        %let CNT_00 = %sysfunc(attrn(&amp;amp;dsid,NOBS));
        %let CC = %sysfunc(close(&amp;amp;dsid));


       /*some codes*/

       data TEMP_0_; set TEMP_0_;
          data TEMP_0_; set TEMP_0_;
               do k = 1 to &amp;amp;CNT_0.;
                  if k &amp;lt;= &amp;amp;CNT_00. then Rand = 1;    /*k and CNT_oo comparison is not properly evaluated*/
                  else Rand = 0;                     /* thus Rand is always 0*/
               end;
          drop k;
          run;

/*some codes*/

%mend TEMP;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 18:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258599#M268991</guid>
      <dc:creator>JMES</dc:creator>
      <dc:date>2016-03-23T18:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Index of Do loop not recognized in IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258610#M268992</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78615"&gt;@JMES﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code is syntactically correct (assuming that the %ENDs for the two %DO loops are hidden in "some codes").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot replicate your issue. When I tested it with appropriate datasets TEMP_0 and TEMP_00, variable RAND was set to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The duplicate line "&lt;FONT face="courier new,courier"&gt;data TEMP_0_; set TEMP_0_;&lt;/FONT&gt;" is redundant. The second data step could be simplified as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEMP_0_;
set TEMP_0_;
Rand=ifn(&amp;amp;CNT_0, &amp;amp;CNT_0 &amp;lt;= &amp;amp;CNT_00, .);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please provide small sample datasets (in the form of a data step) which demonstrate the issue?&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;</description>
      <pubDate>Wed, 23 Mar 2016 19:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258610#M268992</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-23T19:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Index of Do loop not recognized in IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258613#M268993</link>
      <description>&lt;P&gt;I suppose this might happen if your second data set contains 0 observations.&amp;nbsp; But you can make it easy to diagnose.&amp;nbsp; Just add this before you run:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options symbolgen;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you will be able to see the values you are working with for your macro variables.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 19:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258613#M268993</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-23T19:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Index of Do loop not recognized in IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258678#M268994</link>
      <description>&lt;P&gt;Thanks all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realized that the codes that I wrote are not doing what I wanted it to do.&lt;/P&gt;&lt;P&gt;I chaged the codes and working fine now.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 23:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Index-of-Do-loop-not-recognized-in-IF-statement/m-p/258678#M268994</guid>
      <dc:creator>JMES</dc:creator>
      <dc:date>2016-03-23T23:45:04Z</dc:date>
    </item>
  </channel>
</rss>

