<?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 do I create a more efficient Macro to add rows to a table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-more-efficient-Macro-to-add-rows-to-a-table/m-p/373928#M89478</link>
    <description>&lt;P&gt;Thanks for the quick response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Worked perfectly. took about 15 seconds to run. I'll work on the custom values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2017 12:03:59 GMT</pubDate>
    <dc:creator>jlozano1</dc:creator>
    <dc:date>2017-07-07T12:03:59Z</dc:date>
    <item>
      <title>How do I create a more efficient Macro to add rows to a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-more-efficient-Macro-to-add-rows-to-a-table/m-p/373918#M89470</link>
      <description>&lt;P&gt;I have a table that includes a customer name and the difference (in months) between two dates. I need a macro that, based on the number of months in between the two dates, adds that determined amount of rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, my table has 4 columns: Customer Name, Date 1, Date 2 and Months. Months refers to the difference in Months between Date 1 and Date 2. Again, my objective is to add rows below each customer. Number of rows to be added should depend on the number of "Months".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried building some code myself but ir takes forever to run. I am using SAS Enterprise Guide version 7.13&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking for some smart suggestions on how I can create a more efficient method. Table has about 200,000 rows and last time I tried running it, it took more than 8 hours. Any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my attempt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select max(monotonic())&lt;BR /&gt;into : num_rows&lt;BR /&gt;from work.table_template&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put Number of rows is: &amp;amp;num_rows.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;options mprint merror mlogic symbolgen;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro one;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;num_rows.;&lt;BR /&gt;data _null_;&lt;BR /&gt;set work.table_template;&lt;BR /&gt;if _n_ = &amp;amp;i.;&lt;BR /&gt;call symputx('Customer_Name',Customer_Name);&lt;BR /&gt;call symputx('Date1',Date1);&lt;BR /&gt;call symputx('Date2',Date2);&lt;BR /&gt;call symputx('Months',Months);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%do j = 2 %to (&amp;amp;months.-1);&lt;BR /&gt;data _null_;&lt;BR /&gt;call symputx('Date1',intnx('month',&amp;amp;Date1.,1));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;insert into work.table_template&lt;BR /&gt;values ("&amp;amp;Customer_Name.",&amp;amp;Date1.,&amp;amp;Date2.,&amp;amp;Months.);&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend one;&lt;/P&gt;&lt;P&gt;%one;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 11:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-more-efficient-Macro-to-add-rows-to-a-table/m-p/373918#M89470</guid>
      <dc:creator>jlozano1</dc:creator>
      <dc:date>2017-07-07T11:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a more efficient Macro to add rows to a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-more-efficient-Macro-to-add-rows-to-a-table/m-p/373922#M89473</link>
      <description>&lt;P&gt;You're overcomplicating things by lightyears.&lt;/P&gt;
&lt;P&gt;Maxim 11: A macro is not&amp;nbsp; needed.&lt;/P&gt;
&lt;P&gt;Is true for close to 99.99% of cases with SAS beginners.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
do i = 1 to months;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will basically do the expand in one sweep.&lt;/P&gt;
&lt;P&gt;Add custom calculated values in the do loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 11:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-more-efficient-Macro-to-add-rows-to-a-table/m-p/373922#M89473</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-07T11:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a more efficient Macro to add rows to a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-more-efficient-Macro-to-add-rows-to-a-table/m-p/373928#M89478</link>
      <description>&lt;P&gt;Thanks for the quick response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Worked perfectly. took about 15 seconds to run. I'll work on the custom values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 12:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-more-efficient-Macro-to-add-rows-to-a-table/m-p/373928#M89478</guid>
      <dc:creator>jlozano1</dc:creator>
      <dc:date>2017-07-07T12:03:59Z</dc:date>
    </item>
  </channel>
</rss>

