<?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: Conditional Loop Question in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919567#M41191</link>
    <description>&lt;P&gt;Yes, thank you. I flipped the inequality and my eyes just were not catching it. It should be sorted now.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Mar 2024 20:48:54 GMT</pubDate>
    <dc:creator>sas_user_1001</dc:creator>
    <dc:date>2024-03-08T20:48:54Z</dc:date>
    <item>
      <title>Conditional Loop Question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919561#M41187</link>
      <description>&lt;P&gt;I am attempting to create a loop that will capture my data at various window sizes for further evaluation. The problem, at the moment, is that the 'where' statement is only evaluating my first condition, and not the second.&lt;/P&gt;&lt;P&gt;Here's the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let min_year = 1995&lt;/P&gt;&lt;P&gt;%let max_year = 2005&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;%macro loop;&lt;/DIV&gt;&lt;DIV&gt;%local window; %let window = 1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%do i = &amp;amp;min_year. % to &amp;amp;max_year. %by 1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data small_data_roll_wind;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set my_large_data (where = (%eval(&amp;amp;i. - 1) &amp;gt; year1 &amp;lt; (%eval(&amp;amp;i. + 2))));&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%let window = %eval(&amp;amp;window. + 1);&lt;/DIV&gt;&lt;DIV&gt;%end;&lt;/DIV&gt;&lt;DIV&gt;%mend loop;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%loop&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For the most part this works, except that only "&lt;SPAN&gt;(where = (%eval(&amp;amp;i. - 1) &amp;gt; year1" is evaluated. The second component "year1 &amp;lt; (%eval(&amp;amp;i. + 2))));" seems to be completely ignored from what I can tell. I assume I am missing some syntax here, but any insight is appreciated.&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 08 Mar 2024 20:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919561#M41187</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-03-08T20:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Loop Question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919562#M41188</link>
      <description>&lt;P&gt;I think you have a &amp;gt; where you want &amp;lt; .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you intend:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set my_large_data (where = ( %eval(&amp;amp;i. - 1) &amp;lt; year1 &amp;lt; %eval(&amp;amp;i. + 2) ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 20:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919562#M41188</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-03-08T20:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Loop Question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919564#M41189</link>
      <description>&lt;P&gt;You are so very right -- I flipped the inequality and didn't even notice after looking at this for hours. Thanks for being my second set of eyes today!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 20:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919564#M41189</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-03-08T20:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Loop Question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919565#M41190</link>
      <description>&lt;P&gt;Your coding is convoluted.&amp;nbsp; Normal SAS statements can do arithmetic so need to have the %EVAL() in the WHERE= option.&amp;nbsp; Or to use a WHERE= option instead of just a normal WHERE statement for that matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you logic is also strange.&amp;nbsp; You asked for&amp;nbsp;numbers that are both less than X-1 and less than X+2.&amp;nbsp; So that is just the numbers that are less than X-1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect you meant the numbers between the two instead? Which would be those equal to X or X+1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you want a where statement like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data small_data_roll_wind;
  set my_large_data ;
  where (&amp;amp;i. - 1) &amp;lt; year1 &amp;lt; (&amp;amp;i. + 2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps if you are querying a database with an index you might want to use IN operator instead?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where year1 in (&amp;amp;i %eval(&amp;amp;i. + 1));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depends on what functions allow you to take advantage of the index to improve performance.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 20:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919565#M41190</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-08T20:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Loop Question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919567#M41191</link>
      <description>&lt;P&gt;Yes, thank you. I flipped the inequality and my eyes just were not catching it. It should be sorted now.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 20:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-Loop-Question/m-p/919567#M41191</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-03-08T20:48:54Z</dc:date>
    </item>
  </channel>
</rss>

