<?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: Problem with my code with macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506737#M1395</link>
    <description>&lt;P&gt;You always overwrite dataset code1, so only the results of the last macro iteration take effect.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Oct 2018 05:31:28 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-23T05:31:28Z</dc:date>
    <item>
      <title>Problem with my code with macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506734#M1394</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; I use the posted code to generate new vars, but after running the code, I just got one new variable, y20, what's wrong with my code?&lt;/P&gt;
&lt;P&gt;Thanks a lot!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro abc;
    %do i=1 %to 20;
    data code1;
        set code;
        y&amp;amp;i=x&amp;amp;i/2;
    run;
    %end;
    %mend;
%abc&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 05:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506734#M1394</guid>
      <dc:creator>owenwqp1</dc:creator>
      <dc:date>2018-10-23T05:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with my code with macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506737#M1395</link>
      <description>&lt;P&gt;You always overwrite dataset code1, so only the results of the last macro iteration take effect.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 05:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506737#M1395</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-23T05:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with my code with macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506741#M1396</link>
      <description>&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you so much Kurtbremser!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 06:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506741#M1396</guid>
      <dc:creator>owenwqp1</dc:creator>
      <dc:date>2018-10-23T06:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with my code with macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506746#M1397</link>
      <description>&lt;P&gt;More importantly, why are you creating 20 datasets for the same data?&amp;nbsp; This uses more disk space, is slower, and is far harder to maintain.&amp;nbsp; I am pretty certain after seeing this type of code a lot, you will then either be merging those datasets, or looping over them using further messy macro code.&amp;nbsp; Don't.&amp;nbsp; You can simply do one step:&lt;/P&gt;
&lt;PRE&gt;data code1 (drop=i);
  set code;
  array y{20} 8.;
  array x{8};   /* assumes it already exists in code */
  do i=1 to 20;
    y{i}=x{i}/2;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Or you could create a normalised version of the above with each item in a row rather than columns which is a better structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 07:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506746#M1397</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-23T07:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with my code with macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506807#M1404</link>
      <description>&lt;P&gt;It is possible to use macro language to generate 20 assignment statements within the same DATA step.&amp;nbsp; You just need to rearrange the pieces of your program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro abc;
   data code1;
      set code;
      %do i=1 %to 20;
          y&amp;amp;i=x&amp;amp;i/2;
      %end;
   run;
%mend abc;
%abc&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Oct 2018 12:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-my-code-with-macro/m-p/506807#M1404</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-23T12:43:38Z</dc:date>
    </item>
  </channel>
</rss>

