<?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: Using %IF to control rows to process in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713772#M220252</link>
    <description>&lt;P&gt;My real work is a macro, so I make this to replicate the situation.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
    <pubDate>Sun, 24 Jan 2021 22:42:03 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2021-01-24T22:42:03Z</dc:date>
    <item>
      <title>Using %IF to control rows to process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713770#M220250</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;In my original code below, SAS processes all rows.&lt;/P&gt;
&lt;P&gt;However, I only want SAS to process rows with day_of_interest=1.&lt;/P&gt;
&lt;P&gt;I put %IF into the code but it doesn't work.&lt;/P&gt;
&lt;P&gt;(In my actual work, it is a marco process)&lt;/P&gt;
&lt;P&gt;Can anyone please help me to fix it?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input id sale max min day_of_interest;
datalines;
1 5 70 4 0
2 2 70 4 0
3 10 30 4 1
4 100 50 17 1
5 15 50 14 0
;run;

data want;
set have nobs=totalobs;
drop i new_id new_max new_min;
exit_id=.;
i+1;
	do j=i+1 to totalobs until (exit_id^=.);
		set have (keep = id max min rename=(id=new_id max=new_max min=new_min)) point=j;
		if sale&amp;gt;new_max or sale&amp;lt;new_min then exit_id=new_id;
	end;
run;

*------------MACRO----------------------;
%Macro xx;
data want;
set have nobs=totalobs;
exit_id=.;
i+1;
%IF day_of_interest=1 %THEN %DO;
	do j=i+1 to totalobs until (exit_id^=.);
		set have (keep = id max min rename=(id=new_id max=new_max min=new_min)) point=j;
		if sale&amp;gt;new_max or sale&amp;lt;new_min then exit_id=new_id;
	end;
%END;
run;
%MEnd;
%xx;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 22:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713770#M220250</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2021-01-24T22:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using %IF to control rows to process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713771#M220251</link>
      <description>&lt;P&gt;Try using DATA step IF THEN ELSE instead of macro %IF %THEN %ELSE&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 22:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713771#M220251</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-24T22:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using %IF to control rows to process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713772#M220252</link>
      <description>&lt;P&gt;My real work is a macro, so I make this to replicate the situation.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 22:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713772#M220252</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2021-01-24T22:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using %IF to control rows to process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713775#M220254</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My real work is a macro, so I make this to replicate the situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That doesn't mean you have to use the macro %IF in this specific situation, especially since it will not work here. A macro %IF cannot evaluate the value of a data step variable to see if its value is equal to 1, as you are using here. A data step IF can evaluate the value of the data step variable to see if it is equal to 1.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 22:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713775#M220254</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-24T22:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using %IF to control rows to process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713777#M220256</link>
      <description>&lt;P&gt;1. The macro language should only be used when necessary, as it can confuse untrained users.&lt;/P&gt;
&lt;P&gt;2. A trained user would know that the macro processor cannot know the value of a data step variable.&lt;/P&gt;
&lt;P&gt;Hence&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;'s valid recommendatoin.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 23:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713777#M220256</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-01-24T23:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using %IF to control rows to process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713789#M220268</link>
      <description>&lt;P&gt;Thank you all for helping.&lt;/P&gt;
&lt;P&gt;I got it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have nobs=totalobs;
drop i new_id new_max new_min;
exit_id=.;
i+1;
if day_of_interest=1 then do;
	do j=i+1 to totalobs until (exit_id^=.);
		set have (keep = id max min rename=(id=new_id max=new_max min=new_min)) point=j;
		if sale&amp;gt;new_max or sale&amp;lt;new_min then exit_id=new_id;
	end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jan 2021 00:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-to-control-rows-to-process/m-p/713789#M220268</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2021-01-25T00:46:40Z</dc:date>
    </item>
  </channel>
</rss>

