<?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: SAS beginner - why does my macro not work? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869495#M343429</link>
    <description>&lt;P&gt;Show us the code that works to accomplish your task for 3 "iterations" without any macro code involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then we can suggest how to make a macro that accomplishes that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a minimum you need to provide an example of your data set and the actual macro call that you used.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 00:53:04 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-04-13T00:53:04Z</dc:date>
    <item>
      <title>SAS beginner - why does my macro not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869373#M343387</link>
      <description>&lt;P&gt;Hey, I am a beginner in SAS so I appreciate any help.&lt;/P&gt;
&lt;P&gt;I want to iterate the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sampledata;
set sampledata;
if variable_i = j then indicator_variable_i = 1;
else indicator_variable_i = 0;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I want to iterate it over i and j. "other_variable" does not exist before so it should be a new variable like an indicator.&lt;/P&gt;
&lt;P&gt;I tried using my macro, but It somewhat not working &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro zeroone(variable, indicator_variable);

data sampledata;
set sampledata;
%do i=0 %to 6;
&amp;amp;indicator_variable&amp;amp;i = 0;
%do j=1 %to 3;
%If &amp;amp;variable&amp;amp;j = &amp;amp;i %then %do;
&amp;amp;indicator_variable&amp;amp;i = 1;
%end;
%end;
%end;
run;
%mend zeroone;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does anyone have any idea for me? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 22:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869373#M343387</guid>
      <dc:creator>kazue58</dc:creator>
      <dc:date>2023-04-12T22:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS beginner - why does my macro not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869490#M343424</link>
      <description>&lt;P&gt;I modified your post to make it bit more legible (it looked like a wall of text/code mixed together). I did not format the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How is it not working? How did you call the macro, that is not shown.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looping over variables like this screams arrays not macros to me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441738"&gt;@kazue58&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey, I am a beginner in SAS so I appreciate any help.&lt;/P&gt;
&lt;P&gt;I want to iterate the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sampledata;
set sampledata;
if variable_i = j then indicator_variable_i = 1;
else indicator_variable_i = 0;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I want to iterate it over i and j. "other_variable" does not exist before so it should be a new variable like an indicator.&lt;/P&gt;
&lt;P&gt;I tried using my macro, but It somewhat not working &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro zeroone(variable, indicator_variable);

data sampledata;
set sampledata;
%do i=0 %to 6;
&amp;amp;indicator_variable&amp;amp;i = 0;
%do j=1 %to 3;
%If &amp;amp;variable&amp;amp;j = &amp;amp;i %then %do;
&amp;amp;indicator_variable&amp;amp;i = 1;
%end;
%end;
%end;
run;
%mend zeroone;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does anyone have any idea for me? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 22:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869490#M343424</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-12T22:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS beginner - why does my macro not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869491#M343425</link>
      <description>&lt;P&gt;It is not clear what you mean by "iterate".&amp;nbsp; Iterate what ? over what range of values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first data step can be simplified to use just an assignment statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sampledata_update ;
  set sampledata;
  indicator_variable_i = (variable_i = j);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which looks like you are just trying to test if the value of J is equal to value of VARIABLE_I.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really have variables named J and VARIABLE_I?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps the purpose would be clearer if you used variable names that have some meaning?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what the data step would look like when there are two variables to test?&amp;nbsp; How many new variables would you want to create?&amp;nbsp; How would you create them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What about for three?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 23:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869491#M343425</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-12T23:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS beginner - why does my macro not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869495#M343429</link>
      <description>&lt;P&gt;Show us the code that works to accomplish your task for 3 "iterations" without any macro code involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then we can suggest how to make a macro that accomplishes that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a minimum you need to provide an example of your data set and the actual macro call that you used.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 00:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-beginner-why-does-my-macro-not-work/m-p/869495#M343429</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-13T00:53:04Z</dc:date>
    </item>
  </channel>
</rss>

