<?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: Please help me with the macro code with do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-with-the-macro-code-with-do-loop/m-p/35575#M7043</link>
    <description>Thanks so much! That worked! I appreciate your help!</description>
    <pubDate>Wed, 30 Dec 2009 00:17:08 GMT</pubDate>
    <dc:creator>maggie00</dc:creator>
    <dc:date>2009-12-30T00:17:08Z</dc:date>
    <item>
      <title>Please help me with the macro code with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-with-the-macro-code-with-do-loop/m-p/35573#M7041</link>
      <description>I have two files: file1 has 300 companies, with id 1 to 300, file 2 has 600 products. How can I make a macro so that I have a file with each (300) firm with 600 products? Thanks so much!&lt;BR /&gt;
&lt;BR /&gt;
I wrote following macro codes named time, but it does not work. (My logic is: pick out each firm first, merge it with file 2, so that I have 300 files each with 600 firms. Then I can just merge these 300 files together into what I need.)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro time;&lt;BR /&gt;
data dd&amp;amp;i; set file1; &lt;BR /&gt;
%do i=1 %to 300; if id_use=&amp;amp;i;&lt;BR /&gt;
data final&amp;amp;i; merge file2 dd&amp;amp;i; by year quarter;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend time;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 29 Dec 2009 23:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help-me-with-the-macro-code-with-do-loop/m-p/35573#M7041</guid>
      <dc:creator>maggie00</dc:creator>
      <dc:date>2009-12-29T23:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me with the macro code with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-with-the-macro-code-with-do-loop/m-p/35574#M7042</link>
      <description>Not that I understand the business logic behind having all 600 hundred products joined with all 300 companies - but this would be called a cartesian product which is best produced using SQL syntax.&lt;BR /&gt;
&lt;BR /&gt;
No need to use macro code.&lt;BR /&gt;
&lt;BR /&gt;
Hope the following example will give you an idea how to achieve what you're after.&lt;BR /&gt;
&lt;BR /&gt;
data company;&lt;BR /&gt;
  do company_id=1 to 300;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data product;&lt;BR /&gt;
  do product_id=1 to 600;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table CompanyProduct as&lt;BR /&gt;
    select *&lt;BR /&gt;
      from company,product&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
P.S: In "normal" life one would have 3 tables: "company", "product" and a bridge table "CompanyProduct".&lt;BR /&gt;
The bridge table would contain the keys for "company" and "product" for the cases where a company also offers this product. There might also be additional bridge informations in the table like the date when the company started to offer the product,... and so on.</description>
      <pubDate>Wed, 30 Dec 2009 00:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help-me-with-the-macro-code-with-do-loop/m-p/35574#M7042</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-12-30T00:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me with the macro code with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-with-the-macro-code-with-do-loop/m-p/35575#M7043</link>
      <description>Thanks so much! That worked! I appreciate your help!</description>
      <pubDate>Wed, 30 Dec 2009 00:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help-me-with-the-macro-code-with-do-loop/m-p/35575#M7043</guid>
      <dc:creator>maggie00</dc:creator>
      <dc:date>2009-12-30T00:17:08Z</dc:date>
    </item>
  </channel>
</rss>

