<?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: Sampling with conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/558398#M155853</link>
    <description>&lt;P&gt;I just want to point out that the question says&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;EM&gt;&amp;gt; The sample should include all available distinct values from three columns&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The PROC SURVEYSELECT code that you marked as "correct" does not necessarily "include all available distinct values." It simply extracts 500 random observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, it might be impossible to satisfy that constraint. For example, if X1 = _N_, then there are 1 million distinct values and no subset of 500 observations can include all distinct values. If you want to include all distinct values, you would have to sort the data, then &lt;A href="https://blogs.sas.com/content/iml/2018/02/26/how-to-use-first-variable-and-last-variable-in-a-by-group-analysis-in-sas.html" target="_self"&gt;use the FIRST.VAR technique&lt;/A&gt; to extract the distinct combinations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by x1 - x3;
run;

data distinct;
   set have;
   by x1 - x3;
   if first.x1 | first.x2 | first.x3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This method is unlikely to create 500 observations.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 May 2019 18:00:15 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2019-05-13T18:00:15Z</dc:date>
    <item>
      <title>Sampling with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556705#M155107</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have never done sampling in SAS. I have a population table with a million rows. I will have to extract 500 entries that meet the following criteria.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The sample should include all available distinct values from three column&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;How can I do this in SAS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 10:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556705#M155107</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2019-05-07T10:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sampling with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556716#M155109</link>
      <description>&lt;P&gt;Hi, you can use the proc surveyselect :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have ;
set Yourtable ;
keep var1 var2 var3 ;
run ;

proc surveyselect data=have
   method=srs n=500 out=SampleSRS;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 10:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556716#M155109</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-05-07T10:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sampling with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556844#M155150</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a follow up to this questions. I need random samples. However if the number of observations from a 15% sample are less than 10 records, then I need the program to select 10 random records. Is there any way to do this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 16:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556844#M155150</guid>
      <dc:creator>colabear</dc:creator>
      <dc:date>2019-05-07T16:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Sampling with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556850#M155153</link>
      <description>&lt;P&gt;You can use the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_surveyselect_syntax01.htm&amp;amp;docsetVersion=15.1&amp;amp;locale=en#statug.surveyselect.selectnmin" target="_self"&gt;NMIN=&lt;/A&gt;&amp;nbsp;option to specify the minimum sample size.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyselect rate=.15 nmin=10;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 16:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556850#M155153</guid>
      <dc:creator>Watts</dc:creator>
      <dc:date>2019-05-07T16:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sampling with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556929#M155197</link>
      <description>&lt;P&gt;Thank you very much!&amp;nbsp;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 20:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/556929#M155197</guid>
      <dc:creator>colabear</dc:creator>
      <dc:date>2019-05-07T20:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sampling with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/558398#M155853</link>
      <description>&lt;P&gt;I just want to point out that the question says&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;EM&gt;&amp;gt; The sample should include all available distinct values from three columns&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The PROC SURVEYSELECT code that you marked as "correct" does not necessarily "include all available distinct values." It simply extracts 500 random observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, it might be impossible to satisfy that constraint. For example, if X1 = _N_, then there are 1 million distinct values and no subset of 500 observations can include all distinct values. If you want to include all distinct values, you would have to sort the data, then &lt;A href="https://blogs.sas.com/content/iml/2018/02/26/how-to-use-first-variable-and-last-variable-in-a-by-group-analysis-in-sas.html" target="_self"&gt;use the FIRST.VAR technique&lt;/A&gt; to extract the distinct combinations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by x1 - x3;
run;

data distinct;
   set have;
   by x1 - x3;
   if first.x1 | first.x2 | first.x3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This method is unlikely to create 500 observations.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 18:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sampling-with-conditions/m-p/558398#M155853</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-05-13T18:00:15Z</dc:date>
    </item>
  </channel>
</rss>

