<?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: Random sampling in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458929#M70193</link>
    <description>&lt;P&gt;Follow what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; said.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.zipcode;
 call streaminit(12345678);
 r=rand('uniform');
run;

proc sort data=have ;
by STATE r;
run;

data want;
 set have;
 by STATE;
 if first.STATE then Random=rand('bern',0.1) ;
 drop r;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 May 2018 08:43:24 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-05-01T08:43:24Z</dc:date>
    <item>
      <title>Random sampling</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458883#M70188</link>
      <description>&lt;P&gt;I am trying to generate a 1% random sample from my data set, but I only want 1 of each distinct value in a variable. For example, if I have a set that looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Company Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Project Number &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Joint Company&lt;/P&gt;&lt;P&gt;CompA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 553 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CompX&lt;/P&gt;&lt;P&gt;CompA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 552 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CompY&lt;/P&gt;&lt;P&gt;CompB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 133 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CompZ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my random sample, I would only want CompA chosen once, not multiple times due to being in multiple rows. So, I need a 1% random sample using variable CompName. In addition, I do not want it to produce a new data set. Instead, I want a new variable created (let's say, "Random"), where a value of 1 means that row was selected for the random sample, and '.' or '0' means it was not selected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does that make sense? I have tried both proc surveyselect and proc sql and cannot 1) get distinct values instead of duplicates and 2) generate a new column in the same data set (or even a new data set that has all the original variables in it).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 02:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458883#M70188</guid>
      <dc:creator>slobber</dc:creator>
      <dc:date>2018-05-01T02:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Random sampling</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458891#M70189</link>
      <description>&lt;P&gt;Add a random number to your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort data by company, random number&lt;/P&gt;
&lt;P&gt;Create a random Bernoulli variable that has a 1% probability at the start of each company.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 03:24:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458891#M70189</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-01T03:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Random sampling</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458892#M70190</link>
      <description>&lt;P&gt;I'm not sure what you mean by adding a random number to my data?&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 03:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458892#M70190</guid>
      <dc:creator>slobber</dc:creator>
      <dc:date>2018-05-01T03:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Random sampling</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458894#M70191</link>
      <description>&lt;P&gt;Combine&amp;nbsp;cluster sampling with stratified sampling. For example, to get a sample of 10 car models, but never more than one per make:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Select 10 makes */
proc surveyselect data=sashelp.cars sampsize=10 outall
    out=makeSample(rename=selected=selectedMake);
samplingunit make;
run;

/* Select one model from every make */
proc surveyselect data=makeSample sampsize=1 outall 
    out=modelSample(rename=selected=selectedModel);
strata make;
run;

/* Select the selected model for every selected make */
data sample;
set modelSample;
selected = selectedMake and selectedModel;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example assumes that the data is sorted by make.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 04:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458894#M70191</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-05-01T04:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Random sampling</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458929#M70193</link>
      <description>&lt;P&gt;Follow what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; said.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.zipcode;
 call streaminit(12345678);
 r=rand('uniform');
run;

proc sort data=have ;
by STATE r;
run;

data want;
 set have;
 by STATE;
 if first.STATE then Random=rand('bern',0.1) ;
 drop r;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 May 2018 08:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Random-sampling/m-p/458929#M70193</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-01T08:43:24Z</dc:date>
    </item>
  </channel>
</rss>

