<?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: mod function in macro do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874109#M345323</link>
    <description>&lt;P&gt;Your code (once corrected to use %IF and %SYSFUNC) will do nothing, so it's not worth bothering with.&lt;/P&gt;
&lt;P&gt;Rule #1 of macro development: start with&amp;nbsp;&lt;EM&gt;working, non macro&lt;/EM&gt;&amp;nbsp;code. So please show the code you want to make dynamic, and describe what needs to be repeated, and how.&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2023 11:27:27 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-05-05T11:27:27Z</dc:date>
    <item>
      <title>mod function in macro do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874067#M345303</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xyz;
%do i=1 %to 20 ;
if mod(%eval(&amp;amp;i,2))=0 %then %do;
%end;
%end;
%mend;

%xyz;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;error&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 06:07:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874067#M345303</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2023-05-05T06:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: mod function in macro do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874072#M345304</link>
      <description>&lt;P&gt;Do what?&lt;/P&gt;
&lt;P&gt;Your "if" is wrong to execute in macro processing, it should be %if.&lt;/P&gt;
&lt;P&gt;To call data step functions you have to use %sysfunc(function(parameters))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro xyz;
   %do i=1 %to 20 ;
      %if %sysfunc (mod(&amp;amp;i,2))=0 %then %do;
      %end;
   %end;
%mend;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 06:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874072#M345304</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-05T06:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: mod function in macro do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874074#M345308</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xyz;
   %do i=1 %to 20 ;
   data even;
      %if %sysfunc (mod(&amp;amp;i,2))=0 %then %do;
      %end;
      run;
   %end;
%mend;

%xyz;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2023 06:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874074#M345308</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2023-05-05T06:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: mod function in macro do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874075#M345309</link>
      <description>To macro language, mod is not a function. It is just the three letters: mod. To get macro language to treat mod as a function (and to clean up a couple of smaller errors along the way), try this untested version:&lt;BR /&gt;&lt;BR /&gt;%if %sysfunc(mod(&amp;amp;amp;i,2))=0 %then %do;&lt;BR /&gt;&lt;BR /&gt;In fact, in this particular case, you could instead get rid of the mod function if you so choose. Since macro language drops the remainder when it applies %eval, you could try:&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;amp;i = &amp;amp;amp;i/ 2 * 2 %then %do;</description>
      <pubDate>Fri, 05 May 2023 06:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874075#M345309</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-05-05T06:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: mod function in macro do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874077#M345311</link>
      <description>Not fair.  You can't change the problem by adding a DATA statement and a RUN statement.  The answer would change as well.  Try showing the DATA step code and the results that you hope the program will generate.  You may not need any macro language at all.</description>
      <pubDate>Fri, 05 May 2023 07:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874077#M345311</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-05-05T07:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: mod function in macro do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874078#M345312</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xyz;
   %do i=1 %to 20 ;
   data even;
      %if %sysfunc (mod(&amp;amp;i,2))=0 %then %do;
      %end;
      run;
   %end;
%mend;

%xyz;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;NOW you really need to describe everything that you are actually attempting to do. %if&amp;nbsp; code does not recognize the values of data step variables. Macro statements inside data step must generate valid data step (or other procedure) code. Since the code you show does not generate data step code it does nothing except create a data set named even, with no variables and gets overwritten 19 times after initial creation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point I would say that one possible "solution" is : 42 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 12:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874078#M345312</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-05T12:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: mod function in macro do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874095#M345316</link>
      <description>&lt;P&gt;As always, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt; we need much more explanation from you. Your posts are consistently too brief, causing us to guess and often guess wrong and then we have to ask follow-up question after follow-up question. Explain. Provide details about what you are trying to do, in words, not SAS code, and explaining the background and reasons. Emphasis on details. Emphasis on background. Emphasis on explain. Don't make us constantly ask you for additional details and ask why you are doing this; provide all relevant details in the first post. We're trying to help you, but you have to help us.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 10:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874095#M345316</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-05T10:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: mod function in macro do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874109#M345323</link>
      <description>&lt;P&gt;Your code (once corrected to use %IF and %SYSFUNC) will do nothing, so it's not worth bothering with.&lt;/P&gt;
&lt;P&gt;Rule #1 of macro development: start with&amp;nbsp;&lt;EM&gt;working, non macro&lt;/EM&gt;&amp;nbsp;code. So please show the code you want to make dynamic, and describe what needs to be repeated, and how.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 11:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mod-function-in-macro-do-loop/m-p/874109#M345323</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-05T11:27:27Z</dc:date>
    </item>
  </channel>
</rss>

