<?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: How do I randomly split a dataset with1399 unique observations into 2 datasets with 1000 vs. 399 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736107#M229310</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do ID = 1 to 1399;
    output;
  end;
run;


data r1;
  set have;
  call streaminit(42);
  r = rand('uniform');
run;
proc sort data = r1;
  by r;
run;

data want1000 want399;
  set r1;
  drop r;

  if 1000 =&amp;gt; _N_ then output want1000;
                 else output want399;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Apr 2021 19:55:02 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2021-04-21T19:55:02Z</dc:date>
    <item>
      <title>How do I randomly split a dataset with1399 unique observations into 2 datasets with 1000 vs. 399 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736094#M229308</link>
      <description>&lt;P&gt;How do I randomly split a dataset with1399 unique observations into 2 datasets with 1000 vs. 399 obs?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 19:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736094#M229308</guid>
      <dc:creator>Denali</dc:creator>
      <dc:date>2021-04-21T19:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I randomly split a dataset with1399 unique observations into 2 datasets with 1000 vs. 399</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736107#M229310</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do ID = 1 to 1399;
    output;
  end;
run;


data r1;
  set have;
  call streaminit(42);
  r = rand('uniform');
run;
proc sort data = r1;
  by r;
run;

data want1000 want399;
  set r1;
  drop r;

  if 1000 =&amp;gt; _N_ then output want1000;
                 else output want399;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Apr 2021 19:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736107#M229310</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-04-21T19:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I randomly split a dataset with1399 unique observations into 2 datasets with 1000 vs. 399</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736241#M229313</link>
      <description>&lt;P&gt;one more without sorting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do ID = 1 to 1399;
    output;
  end;
run;


data want1000 want399;

  call streaminit(42);
  
  declare hash H();
  H.defineKey("curobs");
  H.defineDone();

  do while(H.num_items&amp;lt;399);
    curobs = rand('integer', 1, 1399);
    H.replace(); 
  end;

  do until(eof);
    set have end=eof curobs=curobs;
    if H.check() then output want1000;
                 else output want399;
  end;&lt;BR /&gt;stop;
run;

/* test */
proc sql;
  select * from want1000
  intersect
  select * from want399
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Apr 2021 20:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736241#M229313</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-04-21T20:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I randomly split a dataset with1399 unique observations into 2 datasets with 1000 vs. 399</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736249#M229317</link>
      <description>&lt;P&gt;PROC SURVEYSELECT is typically used for sample selection.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, because you have two groups that are mutually exclusive, you can use the OUTALL option to output all records.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you select a sample of 1000, but all records are outputted with a variable called SELECTED that will indicate if a variable is in the sample.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Illustrated here, using SASHELP.STOCKS, with a sample of 300 and the remainder, 399 in the second group. No sorting required, proc contents and proc freq are for illustrative purposes only.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will want to set a SEED so that your sample is reproducible, ie if you run the exact same data through it again with the same seed it will generate the same sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=sashelp.stocks;
run;


proc surveyselect data=sashelp.stocks method=srs sampsize=300 out=sample_selected outall seed=50;
run;

proc freq data=sample_selected;
table selected;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140136"&gt;@Denali&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How do I randomly split a dataset with1399 unique observations into 2 datasets with 1000 vs. 399 obs?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 20:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-randomly-split-a-dataset-with1399-unique-observations/m-p/736249#M229317</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-21T20:44:53Z</dc:date>
    </item>
  </channel>
</rss>

