<?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 Replicate a single row of data n times in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/52539#M11092</link>
    <description>Suppose I have the following dataset.&lt;BR /&gt;
&lt;BR /&gt;
id  var1 var2 var3. &lt;BR /&gt;
1 1 4 6&lt;BR /&gt;
2 7 4 0&lt;BR /&gt;
3 1 9 6&lt;BR /&gt;
&lt;BR /&gt;
How do I replicate each observation (1,2, and 3) twice so that the final output looks like....&lt;BR /&gt;
&lt;BR /&gt;
1 1 4 6&lt;BR /&gt;
1 1 4 6&lt;BR /&gt;
2 7 4 0&lt;BR /&gt;
2 7 4 0&lt;BR /&gt;
3 1 9 6&lt;BR /&gt;
3 1 9 6&lt;BR /&gt;
&lt;BR /&gt;
One (inefficient) way of doing this is to make two identical datasets and merge them with a set statement. Is there a more efficient way of doing this. &lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: DB_ECON

Message was edited by: DB_ECON</description>
    <pubDate>Mon, 19 Jul 2010 13:21:31 GMT</pubDate>
    <dc:creator>DB_ECON</dc:creator>
    <dc:date>2010-07-19T13:21:31Z</dc:date>
    <item>
      <title>Replicate a single row of data n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/52539#M11092</link>
      <description>Suppose I have the following dataset.&lt;BR /&gt;
&lt;BR /&gt;
id  var1 var2 var3. &lt;BR /&gt;
1 1 4 6&lt;BR /&gt;
2 7 4 0&lt;BR /&gt;
3 1 9 6&lt;BR /&gt;
&lt;BR /&gt;
How do I replicate each observation (1,2, and 3) twice so that the final output looks like....&lt;BR /&gt;
&lt;BR /&gt;
1 1 4 6&lt;BR /&gt;
1 1 4 6&lt;BR /&gt;
2 7 4 0&lt;BR /&gt;
2 7 4 0&lt;BR /&gt;
3 1 9 6&lt;BR /&gt;
3 1 9 6&lt;BR /&gt;
&lt;BR /&gt;
One (inefficient) way of doing this is to make two identical datasets and merge them with a set statement. Is there a more efficient way of doing this. &lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: DB_ECON

Message was edited by: DB_ECON</description>
      <pubDate>Mon, 19 Jul 2010 13:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/52539#M11092</guid>
      <dc:creator>DB_ECON</dc:creator>
      <dc:date>2010-07-19T13:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replicate a single row of data n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/52540#M11093</link>
      <description>Just hardcode two OUTPUT statements in a DATA step with your SET statement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 19 Jul 2010 13:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/52540#M11093</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-19T13:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Replicate a single row of data n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/52541#M11094</link>
      <description>Hi:&lt;BR /&gt;
  Regarding:&lt;BR /&gt;
&lt;B&gt;merge them with a set statement&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
The SET statement allows you to bring datasets together VERTICALLY, either:&lt;BR /&gt;
1) stack datasets (dataset 1 has 3 obs, dataset 2 has 3 obs) the final dataset will have 6 obs, The first dataset listed on the SET statement will contribute the first group of observations; the dataset listed second on the SET statement will contribute the second group of observations.&lt;BR /&gt;
 &lt;BR /&gt;
2) interleave datasets -- with the above scenario, you would still end up with 6 obs, but in interleaved order.&lt;BR /&gt;
 &lt;BR /&gt;
The MERGE statement allows you to join datasets HORIZONTALLY -- so for example, if you have 3 obs in both datasets and all 3 obs in both datasets match on a BY variable, then the output dataset would have 3 observations and each observation would have the variables that came from both datasets.&lt;BR /&gt;
&lt;BR /&gt;
But, as Scott pointed out, the simple solution is to use 2 OUTPUT statements. So you won't need to "merge with a set".&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 19 Jul 2010 14:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/52541#M11094</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-19T14:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replicate a single row of data n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/368626#M87923</link>
      <description>&lt;P&gt;Hi DB_ECON&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can do that very easily by just appending and then sorting them.&lt;/P&gt;&lt;P&gt;Suppose your dataset name is A and you need output in B&lt;/P&gt;&lt;P&gt;Program:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data B;&lt;/P&gt;&lt;P&gt;set A A;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=B;&lt;/P&gt;&lt;P&gt;by ID;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will get your required result in B dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 07:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/368626#M87923</guid>
      <dc:creator>divyanksingh12</dc:creator>
      <dc:date>2017-06-20T07:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Replicate a single row of data n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/538284#M148167</link>
      <description>&lt;P&gt;You can try the following code( as single is your original data set )&lt;/P&gt;&lt;P&gt;data new ;&lt;BR /&gt;set single;&lt;BR /&gt;do i=1 to 2;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=new(drop=i) noobs;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 14:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replicate-a-single-row-of-data-n-times/m-p/538284#M148167</guid>
      <dc:creator>yifan88</dc:creator>
      <dc:date>2019-02-25T14:53:02Z</dc:date>
    </item>
  </channel>
</rss>

