<?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 how to fill up a dataset with samples till a certain sample size is reached ? in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-fill-up-a-dataset-with-samples-till-a-certain-sample-size/m-p/425125#M13068</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two data sets a and b with 200 entries each.&amp;nbsp; While we have the capacity to test 350 samples each month, I have to use one of the data sets each month (in alternating mode so a b a b etc), and top the remaining places up with samples from the other dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So say, for January, I use dataset a and top it up with 150 samples of dataset b.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case I could simply use Proc Sql... obs = 150&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the samples set sizes change every month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do I need to do to :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;choose a and fill up samples from sample set b till samples size = 350.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas are highly welcome.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jan 2018 03:14:47 GMT</pubDate>
    <dc:creator>Anna_NZ</dc:creator>
    <dc:date>2018-01-05T03:14:47Z</dc:date>
    <item>
      <title>how to fill up a dataset with samples till a certain sample size is reached ?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-fill-up-a-dataset-with-samples-till-a-certain-sample-size/m-p/425125#M13068</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two data sets a and b with 200 entries each.&amp;nbsp; While we have the capacity to test 350 samples each month, I have to use one of the data sets each month (in alternating mode so a b a b etc), and top the remaining places up with samples from the other dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So say, for January, I use dataset a and top it up with 150 samples of dataset b.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case I could simply use Proc Sql... obs = 150&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the samples set sizes change every month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do I need to do to :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;choose a and fill up samples from sample set b till samples size = 350.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas are highly welcome.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 03:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/how-to-fill-up-a-dataset-with-samples-till-a-certain-sample-size/m-p/425125#M13068</guid>
      <dc:creator>Anna_NZ</dc:creator>
      <dc:date>2018-01-05T03:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to fill up a dataset with samples till a certain sample size is reached ?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-fill-up-a-dataset-with-samples-till-a-certain-sample-size/m-p/425131#M13069</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181984"&gt;@Anna_NZ&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Here one way to go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_a;
  ds='A';
  do i=1 to 200;
    output;
  end;
run;

data have_b;
  ds='B';
  do i=1 to 200;
    output;
  end;
run;


%let n_sample=350;
%let ds_all=have_a;
%let ds_sample=have_b;

data want(drop=_:);

  /* ds with all records */
  do while(not last_A);
    set &amp;amp;ds_all nobs=nobs_A end=last_A;
    output;
  end;


  /*** based on: http://support.sas.com/kb/24/722.html ***/
  /*  Method 3: Using SAS DATA Step with no sort required  */

  /* Initialize _K to the number of sample obs needed and _N to the */
  /*  total number of obs in the data set.                          */
  _k= &amp;amp;n_sample - nobs_A;
  _n=nobs_A;

  do while(1);

    set &amp;amp;ds_sample;

    /* To randomly select the first observation for the sample, use the */
    /* fact that each obs in the data set has an equal chance of being  */
    /* selected: k/n. If a random number between 0 and 1 is less than   */
    /* or equal to k/n, we select that the first obs for our sample     */
    /* and also adjust k and the number of obs needed to complete the   */
    /* sample.                                                          */

     if ranuni(0) &amp;lt;= _k/_n then
      do;
        output;
        _k=_k-1;
      end;

    /* At every iteration, adjust N, the number of obs left to */
    /* sample from.                                            */
    _n=_n-1;

    /* Once the desired number of sample points are taken, stop iterating */
    if _k=0 then leave;

  end;

  stop;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jan 2018 04:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/how-to-fill-up-a-dataset-with-samples-till-a-certain-sample-size/m-p/425131#M13069</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-01-05T04:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to fill up a dataset with samples till a certain sample size is reached ?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-fill-up-a-dataset-with-samples-till-a-certain-sample-size/m-p/425143#M13071</link>
      <description>Grab the number of records in each table. Subtract them and create a macro variable with that value, then use that in your SQL code. &lt;BR /&gt;&lt;BR /&gt;Here’s some ways to get those numbers&lt;BR /&gt;&lt;A href="http://www.sascommunity.org/wiki/Determining_the_number_of_observations_in_a_SAS_data_set_efficiently" target="_blank"&gt;http://www.sascommunity.org/wiki/Determining_the_number_of_observations_in_a_SAS_data_set_efficiently&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Jan 2018 04:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/how-to-fill-up-a-dataset-with-samples-till-a-certain-sample-size/m-p/425143#M13071</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-05T04:58:05Z</dc:date>
    </item>
  </channel>
</rss>

