<?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: Create multiple observations from a single one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-observations-from-a-single-one/m-p/15828#M2118</link>
    <description>Hi Sweettravel,&lt;BR /&gt;
&lt;BR /&gt;
You can use the output statement [along with a do loop] to help print duplicate records.  &lt;BR /&gt;
&lt;BR /&gt;
Try using the following code:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;data transformed;&lt;BR /&gt;
     set original;&lt;BR /&gt;
     &lt;BR /&gt;
     gender = 0;  /*sets the gender to male*/&lt;BR /&gt;
     do m = 1 to male;&lt;BR /&gt;
         output transformed;&lt;BR /&gt;
     end;&lt;BR /&gt;
     gender = 1; /*  sets the gender to female*/&lt;BR /&gt;
     do f = 1 to female;&lt;BR /&gt;
         output transformed;&lt;BR /&gt;
     end;&lt;BR /&gt;
     keep gender v1-v4;  /*ensures the key variables are kept*/&lt;BR /&gt;
run;&lt;/B&gt;&lt;BR /&gt;
      &lt;BR /&gt;
I will note that the code above assumes male and female are both greater than 0.  If this is not the case, you will need to add a conditional logic check before dropping into the DO loops.  &lt;BR /&gt;
&lt;BR /&gt;
Rambo</description>
    <pubDate>Wed, 13 Oct 2010 04:34:26 GMT</pubDate>
    <dc:creator>Rambo</dc:creator>
    <dc:date>2010-10-13T04:34:26Z</dc:date>
    <item>
      <title>Create multiple observations from a single one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-observations-from-a-single-one/m-p/15827#M2117</link>
      <description>Hi, all&lt;BR /&gt;
I have the original data set like this:&lt;BR /&gt;
Male Female V1 V2 V3 V4&lt;BR /&gt;
3         2           2    4  5    7&lt;BR /&gt;
2        3           6    9   3   8&lt;BR /&gt;
&lt;BR /&gt;
Now I want to transform it into a new data set. Instead of male and female, now I have a new variable "gender", and gender=0 for male, gender=1 for female. If male=3, then repeat the observation 3 times with gender=0; if female=2, then repeat the observation 2 times with gender=1.  &lt;BR /&gt;
&lt;BR /&gt;
The transformed data set should look like:&lt;BR /&gt;
Gender V1 V2 V3 V4&lt;BR /&gt;
  0            2    4  5    7&lt;BR /&gt;
  0            2    4  5    7&lt;BR /&gt;
  0            2    4  5    7&lt;BR /&gt;
  1            2    4  5    7&lt;BR /&gt;
  1            2    4  5    7&lt;BR /&gt;
  0         6    9   3   8&lt;BR /&gt;
  0         6    9   3   8&lt;BR /&gt;
  1         6    9   3   8&lt;BR /&gt;
  1         6    9   3   8&lt;BR /&gt;
  1         6    9   3   8&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
This task is really tricky for me. Wonder whether anyone have an idea of how to implement it. Thanks a lot!</description>
      <pubDate>Wed, 13 Oct 2010 04:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-observations-from-a-single-one/m-p/15827#M2117</guid>
      <dc:creator>sweettravel</dc:creator>
      <dc:date>2010-10-13T04:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple observations from a single one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-observations-from-a-single-one/m-p/15828#M2118</link>
      <description>Hi Sweettravel,&lt;BR /&gt;
&lt;BR /&gt;
You can use the output statement [along with a do loop] to help print duplicate records.  &lt;BR /&gt;
&lt;BR /&gt;
Try using the following code:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;data transformed;&lt;BR /&gt;
     set original;&lt;BR /&gt;
     &lt;BR /&gt;
     gender = 0;  /*sets the gender to male*/&lt;BR /&gt;
     do m = 1 to male;&lt;BR /&gt;
         output transformed;&lt;BR /&gt;
     end;&lt;BR /&gt;
     gender = 1; /*  sets the gender to female*/&lt;BR /&gt;
     do f = 1 to female;&lt;BR /&gt;
         output transformed;&lt;BR /&gt;
     end;&lt;BR /&gt;
     keep gender v1-v4;  /*ensures the key variables are kept*/&lt;BR /&gt;
run;&lt;/B&gt;&lt;BR /&gt;
      &lt;BR /&gt;
I will note that the code above assumes male and female are both greater than 0.  If this is not the case, you will need to add a conditional logic check before dropping into the DO loops.  &lt;BR /&gt;
&lt;BR /&gt;
Rambo</description>
      <pubDate>Wed, 13 Oct 2010 04:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-observations-from-a-single-one/m-p/15828#M2118</guid>
      <dc:creator>Rambo</dc:creator>
      <dc:date>2010-10-13T04:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple observations from a single one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-observations-from-a-single-one/m-p/15829#M2119</link>
      <description>Thanks a lot, Rambo. The code works great on my sample data, I will apply to my large data, too. Saves me lots of time, thanks again!</description>
      <pubDate>Thu, 14 Oct 2010 04:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-observations-from-a-single-one/m-p/15829#M2119</guid>
      <dc:creator>sweettravel</dc:creator>
      <dc:date>2010-10-14T04:10:24Z</dc:date>
    </item>
  </channel>
</rss>

