<?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: Insert rows according to another table rows values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331558#M74531</link>
    <description>&lt;P&gt;Use array processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_a;
input col1 $ col2 $ col3 $ col4 $;
cards;
ZZS KJP UOI RJS
;
run;

data table_b (keep=id value);
set table_a;
array cols {*} col1-col4;
do i1 = 1 to dim(cols);
  do id = 1 to 3;
    value = cols{i1};
    output;
  end;
end;
run;

proc print data=table_b noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;id    value

 1     ZZS 
 2     ZZS 
 3     ZZS 
 1     KJP 
 2     KJP 
 3     KJP 
 1     UOI 
 2     UOI 
 3     UOI 
 1     RJS 
 2     RJS 
 3     RJS 
&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 Feb 2017 15:37:44 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-02-10T15:37:44Z</dc:date>
    <item>
      <title>Insert rows according to another table rows values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331554#M74529</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two tables A and B&lt;/P&gt;&lt;P&gt;In table A I have only one row with an undetermined number of column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my table B I have two columns ID, VALUE with 0 rows.&lt;/P&gt;&lt;P&gt;I would like to insert three rows for each of the A column&lt;/P&gt;&lt;P&gt;The ID would be 1, 2, and 3. The VALUE would be equal to each value of the first (and only row) of table A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exemple My table A is like this:&lt;/P&gt;&lt;P&gt;Col1 Col2 Col3 Col4 ...&lt;/P&gt;&lt;P&gt;ZZS KJP UOI RJS ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My table B should be something like&lt;/P&gt;&lt;P&gt;ID VALUE&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;ZZS&lt;/P&gt;&lt;P&gt;2 ZZS&lt;/P&gt;&lt;P&gt;3 ZZS&lt;/P&gt;&lt;P&gt;1 KJP&lt;/P&gt;&lt;P&gt;2 KJP&lt;/P&gt;&lt;P&gt;3 KJP&lt;/P&gt;&lt;P&gt;1 UOI&lt;/P&gt;&lt;P&gt;2 UOI&lt;/P&gt;&lt;P&gt;3 UOI&lt;/P&gt;&lt;P&gt;1 RJS&lt;/P&gt;&lt;P&gt;2 RJS&lt;/P&gt;&lt;P&gt;3 RJS&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I am a crap in SAS macro I have truly no idea of how to do it...Can you help me?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 15:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331554#M74529</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-02-10T15:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Insert rows according to another table rows values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331556#M74530</link>
      <description>&lt;P&gt;Create a table C, and manually/programmatically enter three rows for the column ID (1, 2, &amp;amp; 3).&lt;/P&gt;
&lt;P&gt;The create&amp;nbsp;B as a join A with C without joining criteria, hence creating a Cartesian&amp;nbsp;product.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 15:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331556#M74530</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-02-10T15:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Insert rows according to another table rows values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331558#M74531</link>
      <description>&lt;P&gt;Use array processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_a;
input col1 $ col2 $ col3 $ col4 $;
cards;
ZZS KJP UOI RJS
;
run;

data table_b (keep=id value);
set table_a;
array cols {*} col1-col4;
do i1 = 1 to dim(cols);
  do id = 1 to 3;
    value = cols{i1};
    output;
  end;
end;
run;

proc print data=table_b noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;id    value

 1     ZZS 
 2     ZZS 
 3     ZZS 
 1     KJP 
 2     KJP 
 3     KJP 
 1     UOI 
 2     UOI 
 3     UOI 
 1     RJS 
 2     RJS 
 3     RJS 
&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 15:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331558#M74531</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-10T15:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Insert rows according to another table rows values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331559#M74532</link>
      <description>&lt;P&gt;Are every single one of the variables in table A the same type, numeric or character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 15:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331559#M74532</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-10T15:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Insert rows according to another table rows values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331564#M74534</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;Thanks for the reply. The problem, in this case is I don't know how many column I wil have. In the example it was 4 but it can be 2, 3, 4, 5, 6, 7...depending on what data I receive&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 15:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331564#M74534</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-02-10T15:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Insert rows according to another table rows values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331566#M74536</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Yes all character&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 15:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331566#M74536</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-02-10T15:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Insert rows according to another table rows values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331576#M74538</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88332"&gt;@fabdu92&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Yes all character&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;'s solution&amp;nbsp; with one very minor change should work. The special list variable _character_ references all character variables in the data set.&lt;/P&gt;
&lt;PRE&gt;data table_b (keep=id value);
set table_a;
array cols {*} _character_;
do i1 = 1 to dim(cols);
  do id = 1 to 3;
    value = cols{i1};
    output;
  end;
end;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 16:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331576#M74538</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-10T16:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Insert rows according to another table rows values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331583#M74540</link>
      <description>&lt;P&gt;Many thanks! Have a good evening &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 16:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-rows-according-to-another-table-rows-values/m-p/331583#M74540</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-02-10T16:20:50Z</dc:date>
    </item>
  </channel>
</rss>

