<?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: Generate Multiple Random Samples of Random Sizes in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471449#M7130</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;this is definitely along the lines of what I want to do. But there must be a version issue as unfortunately this doesn't work for me.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jun 2018 17:15:43 GMT</pubDate>
    <dc:creator>Nate93</dc:creator>
    <dc:date>2018-06-19T17:15:43Z</dc:date>
    <item>
      <title>Generate Multiple Random Samples of Random Sizes</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471433#M7127</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of size 1909. And from this dataset I would like to create 50 random sample (SRS is fine), but the 50 random sample also need to be of a random size between 30% and 80% of the original sample size - so anything between 573 and 1527 observations in my 50 samples (since dataset is 1909 obs).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attempted to use proc surveryselect but this will only work in creating 1 sample. The N= option only seems to take a numeric value rather than a function, as I was trying to put a random number generator here and then wrap this in a loop and do 50 times, but I couldn't get anywhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 16:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471433#M7127</guid>
      <dc:creator>Nate93</dc:creator>
      <dc:date>2018-06-19T16:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Multiple Random Samples of Random Sizes</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471440#M7128</link>
      <description>&lt;P&gt;It might help to provide a more concrete example of what you are attempting to do with a smaller number of starting records and what 2 or 3 groups might look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you might want to use replicate sampling.&lt;/P&gt;
&lt;P&gt;The following will select 3 REPLICATES which I think your 50 might represent and selects 40% of the records, SAMPRATE= 0.4, for each replicate.&lt;/P&gt;
&lt;PRE&gt;proc surveyselect data=sashelp.class reps=3
   samprate= 0.4 out=selected ;
run;&lt;/PRE&gt;
&lt;P&gt;The output data set has a variable named Replicate that indicates which of the 3 reps the record(s) belong to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you mean to randomly change the sample rate for each replicate then that's going to be a different kettle of fish.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 16:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471440#M7128</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-19T16:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Multiple Random Samples of Random Sizes</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471445#M7129</link>
      <description>&lt;P&gt;Assuming you're using the latest version of SAS and SAS/STAT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro generate_random(dsn=, n_samples=, n_min=, n_max=);

%do i=1 %to &amp;amp;n_samples;
proc surveyselect data=&amp;amp;dsn reps=1
   sampsize= %sysfunc(rand(integer, &amp;amp;n_min, &amp;amp;n_max)) out=selected_&amp;amp;i. ;
run;

%end;

%mend;

%generate_random(dsn=sashelp.heart, n_samples=20, n_min=5, n_max=100);&lt;BR /&gt;&lt;BR /&gt;*combine all results into one data set;&lt;BR /&gt;data all_selections;&lt;BR /&gt;set selected_: indsname=source;&lt;BR /&gt;sample = source;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216496"&gt;@Nate93&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset of size 1909. And from this dataset I would like to create 50 random sample (SRS is fine), but the 50 random sample also need to be of a random size between 30% and 80% of the original sample size - so anything between 573 and 1527 observations in my 50 samples (since dataset is 1909 obs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attempted to use proc surveryselect but this will only work in creating 1 sample. The N= option only seems to take a numeric value rather than a function, as I was trying to put a random number generator here and then wrap this in a loop and do 50 times, but I couldn't get anywhere.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 16:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471445#M7129</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-19T16:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Multiple Random Samples of Random Sizes</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471449#M7130</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;this is definitely along the lines of what I want to do. But there must be a version issue as unfortunately this doesn't work for me.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 17:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471449#M7130</guid>
      <dc:creator>Nate93</dc:creator>
      <dc:date>2018-06-19T17:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Multiple Random Samples of Random Sizes</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471461#M7131</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=1909;
%let nSamples=50;

data test;
call streaminit(89868);
do i = 1 to &amp;amp;n;
    x = rand("normal");
    output;
    end;
drop i;
run;

data sampsize;
do sampId = 1 to &amp;amp;nSamples;
    alpha = rand("uniform");
    sampleSize = round(&amp;amp;n * (alpha * 0.3 + (1-alpha) * 0.8));
    output;
    end;
drop alpha;
run;

data temp;
set test;
do sampId = 1 to &amp;amp;nSamples;
    output;
    end;
run;

proc sort data=temp; by sampId; run;

proc surveyselect data=temp sampsize=sampsize out=mySamples;
strata sampId;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jun 2018 17:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471461#M7131</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-19T17:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Multiple Random Samples of Random Sizes</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471469#M7132</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216496"&gt;@Nate93&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;this is definitely along the lines of what I want to do. But there must be a version issue as unfortunately this doesn't work for me.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's likely the random number generator portion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;rand&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;integer&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;n_min&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;n_max&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you find a different way to generate the numbers - try rand uniform with some math to get the&amp;nbsp; intervals instead. rand integer is new to SAS but is a great new option IMO.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 18:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/471469#M7132</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-19T18:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Multiple Random Samples of Random Sizes</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/636052#M8194</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For my dataset, I have created groups, however, I'm wanting to pull a random sample from these groups and then perform a "proc glm" test on the random sample pulled. I don't think I am getting correct results. below is my code that I am attempting.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data auditdata; set auditdata;
if lid=1 and restatement_new=1 then group=1;
else if lid=1 and restatement_new=0 then group=2;
else if lid=0 and restatement_new=1 then group=3;
else if lid=0 and restatement_new=0 then group=4;
run;



data auditdata; set auditdata;
ranum=ranuni(1005);
if ranum&amp;lt;.20 then rsample=1; else rsample=0;
run;



proc glm data=auditdata;
class rsample;
model da da2=rsample;
means rsample/hovtest tukey scheffe bon cldiff clm lines alpha=.05;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Mar 2020 02:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/636052#M8194</guid>
      <dc:creator>Dm95</dc:creator>
      <dc:date>2020-03-31T02:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Multiple Random Samples of Random Sizes</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/636061#M8196</link>
      <description>&lt;P&gt;You would have a greater audience if you posted your question as a new topic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand what you are trying to do, you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc glm data=auditdata;
where rsample = 1;
class group;
model da da2=group;
means group/hovtest tukey scheffe bon cldiff clm lines alpha=.05;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 03:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Generate-Multiple-Random-Samples-of-Random-Sizes/m-p/636061#M8196</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-03-31T03:10:49Z</dc:date>
    </item>
  </channel>
</rss>

