<?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: how to use &amp;amp;&amp;amp;var&amp;amp;i in if condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/466305#M285271</link>
    <description>&lt;P&gt;While it's hard to tell when to use macro statement, when not.&lt;/P&gt;&lt;P&gt;for example: Do I need to put % in the if -then-else statement and do while statement? By the way, can I use "Do i = 1 to n while (condition)" statement here like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO FUNDSOURCE(I);&lt;BR /&gt;DATA SASDATA.STUDENT&amp;amp;I;&lt;BR /&gt;SET SASDATA.STUDENTLIST&amp;nbsp;&lt;BR /&gt;DO M = 1 TO 310&amp;nbsp; WHILE(&amp;amp;&amp;amp;BUDG&amp;amp;I &amp;gt; 0); /*loop through all observations_ALL STUDENTS*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; IF &amp;amp;&amp;amp;BUDG&amp;amp;I LE 3000- FA_TOT1&amp;nbsp; THEN do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DISBURSE = &amp;amp;&amp;amp;BUDG&amp;amp;I;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FA_TOT1+DISBURE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;amp;&amp;amp;BUDG&amp;amp;I - DISBURSE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;ELSE IF &amp;amp;&amp;amp;BUDG&amp;amp;I GT (3000- FA_TOT1)&amp;nbsp; THEN DO;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DISBURSE = 3000-FA_TOT1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FA_TOT1+DISBURSE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;&amp;amp;BUDG&amp;amp;I - DISBURSE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;END;&lt;BR /&gt;END;&lt;BR /&gt;&lt;BR /&gt;IF _n_ &amp;gt; M THEN DELETE; /*if budget are all gone, delete other observations, keep observations only for the student who get funds*/&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND FUNDSOURCE;&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 03:49:44 GMT</pubDate>
    <dc:creator>Chaichai</dc:creator>
    <dc:date>2018-05-31T03:49:44Z</dc:date>
    <item>
      <title>how to use &amp;&amp;var&amp;i in if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/465897#M285267</link>
      <description>&lt;DIV&gt;/* Create macro variables to store restrictions&amp;nbsp;*/&lt;/DIV&gt;&lt;DIV&gt;PROC SQL NOPRINT;&lt;/DIV&gt;&lt;DIV&gt;SELECT RESTRICTIONS&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;INTO :RESTRI1 - :RESTRI35 FROM SASDATA.restriction;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;QUIT;&lt;/DIV&gt;&lt;DIV&gt;%PUT &amp;amp;RESTRI2;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/*the resolved value is: */&lt;/DIV&gt;&lt;DIV&gt;gender = 'M' and state = 'CA'&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/*I want to create a data set sasdata.newlist&amp;amp;i when the ith restriction&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;is &amp;amp;&amp;amp;restri&amp;amp;i (eg: gender = 'M' and state = 'CA')*.&lt;/DIV&gt;&lt;DIV&gt;***While the sasdata.newlist2 contains all data in sasdata.oldlist, the if condition doesn't work. Anybody can help me to solve this problem?*/***&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%Macro testing(I);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;data sasdata.newlist&amp;amp;i;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set sasdata.oldlist;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%if &amp;amp;&amp;amp;restri&amp;amp;i %then; /*I only want the observations which meet the restriction &amp;amp;&amp;amp;restri&amp;amp;I* in this new created dataset/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;run;&lt;/DIV&gt;&lt;DIV&gt;%mend testing;&lt;/DIV&gt;&lt;DIV&gt;%testing(2)&lt;/DIV&gt;</description>
      <pubDate>Wed, 30 May 2018 04:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/465897#M285267</guid>
      <dc:creator>Chaichai</dc:creator>
      <dc:date>2018-05-30T04:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to use &amp;&amp;var&amp;i in if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/465907#M285268</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let restri2=sex='F';
%macro testing(I);
  data T;
    set SASHELP.CLASS;
    where &amp;amp;&amp;amp;restri&amp;amp;i ; 
  run;
%mend testing;
%testing(2)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: There were 9 observations read from the data set SASHELP.CLASS.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; WHERE sex='F';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 05:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/465907#M285268</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-05-30T05:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to use &amp;&amp;var&amp;i in if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/465930#M285269</link>
      <description>&lt;P&gt;Or this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro testing(I);
     data sasdata.newlist&amp;amp;i;
     set sasdata.oldlist;
     if &amp;amp;&amp;amp;restri&amp;amp;i; /* simple subsetting if in data step, and condition replaced */
     run;
%mend testing;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Never try to handle actual data with macro statements (that's what you did with using the macro %if instead of the data step if).&lt;/P&gt;
&lt;P&gt;The subsetting if may be needed in some instances; in this simple example, the where condition as suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; will be sufficient and perform better.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 07:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/465930#M285269</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-30T07:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to use &amp;&amp;var&amp;i in if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/466275#M285270</link>
      <description>Thanks, it works</description>
      <pubDate>Wed, 30 May 2018 22:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/466275#M285270</guid>
      <dc:creator>Chaichai</dc:creator>
      <dc:date>2018-05-30T22:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to use &amp;&amp;var&amp;i in if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/466305#M285271</link>
      <description>&lt;P&gt;While it's hard to tell when to use macro statement, when not.&lt;/P&gt;&lt;P&gt;for example: Do I need to put % in the if -then-else statement and do while statement? By the way, can I use "Do i = 1 to n while (condition)" statement here like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO FUNDSOURCE(I);&lt;BR /&gt;DATA SASDATA.STUDENT&amp;amp;I;&lt;BR /&gt;SET SASDATA.STUDENTLIST&amp;nbsp;&lt;BR /&gt;DO M = 1 TO 310&amp;nbsp; WHILE(&amp;amp;&amp;amp;BUDG&amp;amp;I &amp;gt; 0); /*loop through all observations_ALL STUDENTS*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; IF &amp;amp;&amp;amp;BUDG&amp;amp;I LE 3000- FA_TOT1&amp;nbsp; THEN do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DISBURSE = &amp;amp;&amp;amp;BUDG&amp;amp;I;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FA_TOT1+DISBURE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;amp;&amp;amp;BUDG&amp;amp;I - DISBURSE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;ELSE IF &amp;amp;&amp;amp;BUDG&amp;amp;I GT (3000- FA_TOT1)&amp;nbsp; THEN DO;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DISBURSE = 3000-FA_TOT1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FA_TOT1+DISBURSE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;&amp;amp;BUDG&amp;amp;I - DISBURSE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;END;&lt;BR /&gt;END;&lt;BR /&gt;&lt;BR /&gt;IF _n_ &amp;gt; M THEN DELETE; /*if budget are all gone, delete other observations, keep observations only for the student who get funds*/&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND FUNDSOURCE;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 03:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-amp-amp-var-amp-i-in-if-condition/m-p/466305#M285271</guid>
      <dc:creator>Chaichai</dc:creator>
      <dc:date>2018-05-31T03:49:44Z</dc:date>
    </item>
  </channel>
</rss>

