<?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: Select samples using proc surveyselect with certainty in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/229893#M54435</link>
    <description>&lt;P&gt;Do you all the 100 + 10 random obs.,or 10-6=4 random obs?&lt;/P&gt;</description>
    <pubDate>Wed, 14 Oct 2015 13:30:02 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2015-10-14T13:30:02Z</dc:date>
    <item>
      <title>Select samples using proc surveyselect with certainty/first priority ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/229874#M54433</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I wrote the below code to select 10 samples randomly based on “class” distribution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; list;&lt;/P&gt;
&lt;P&gt;input Class $ Name $ &lt;STRONG&gt;3&lt;/STRONG&gt;-&lt;STRONG&gt;11&lt;/STRONG&gt; Marks ;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;A student1&amp;nbsp; 100&lt;/P&gt;
&lt;P&gt;A student2&amp;nbsp; 100&lt;/P&gt;
&lt;P&gt;A student3&amp;nbsp; 90&lt;/P&gt;
&lt;P&gt;A student4&amp;nbsp; 80&lt;/P&gt;
&lt;P&gt;A student5&amp;nbsp; 70&lt;/P&gt;
&lt;P&gt;A student6&amp;nbsp; 60&lt;/P&gt;
&lt;P&gt;A student7&amp;nbsp; 50&lt;/P&gt;
&lt;P&gt;A student8&amp;nbsp; 40&lt;/P&gt;
&lt;P&gt;A student9&amp;nbsp; 30&lt;/P&gt;
&lt;P&gt;A student10 20&lt;/P&gt;
&lt;P&gt;B student11 100&lt;/P&gt;
&lt;P&gt;B student12 90&lt;/P&gt;
&lt;P&gt;B student13 90&lt;/P&gt;
&lt;P&gt;B student14 80&lt;/P&gt;
&lt;P&gt;B student15 70&lt;/P&gt;
&lt;P&gt;B student16 60&lt;/P&gt;
&lt;P&gt;C student17 100&lt;/P&gt;
&lt;P&gt;C student18 100&lt;/P&gt;
&lt;P&gt;C student19 100&lt;/P&gt;
&lt;P&gt;C student20 50&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* select random samples based on the proportion */&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;surveyselect&lt;/STRONG&gt; data = list out = list_sample method = srs sampsize=&lt;STRONG&gt;10&lt;/STRONG&gt; seed = &lt;STRONG&gt;9876&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;strata class / alloc=proportional;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;freq&lt;/STRONG&gt; data=list_sample;&lt;/P&gt;
&lt;P&gt;table class;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the output samples, only 1 100 marks was selected in each class (totally 100 marks cases=3)&lt;/P&gt;
&lt;P&gt;But now I want to add one more requirement:&lt;/P&gt;
&lt;P&gt;All marks=100(totally 6 cases here) should be included in the samples.&lt;/P&gt;
&lt;P&gt;How can I ensure this? Then I tried usually certainty sampling with the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; list2;&lt;/P&gt;
&lt;P&gt;set list;&lt;/P&gt;
&lt;P&gt;if marks=&lt;STRONG&gt;100&lt;/STRONG&gt; then ranking=&lt;STRONG&gt;3&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;else ranking=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;surveyselect&lt;/STRONG&gt; data = list2 out = list2_sample method = pps certsize=&lt;STRONG&gt;2&lt;/STRONG&gt; sampsize=&lt;STRONG&gt;10&lt;/STRONG&gt; seed = &lt;STRONG&gt;9876&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;strata class / alloc=proportional;&lt;/P&gt;
&lt;P&gt;size ranking;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;freq&lt;/STRONG&gt; data=list2_sample;&lt;/P&gt;
&lt;P&gt;table class;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All 100 marks cases in class A and B were selected, but there is error for class C:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: The number of certainty units exceeds the specified sample size.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My idea is, if&amp;nbsp;&lt;SPAN&gt;number of certainty units exceeds the specified sample size, then just randomly choose among those&amp;nbsp;certainty units to meet the sample size. But I don't know how to fix this problem.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My ultimate result is to select base on proportion to the number of observation (that's why I use proportional allocation), and to select all marks=100 with first priority, the remaining to be selected&amp;nbsp;randomly from the pool.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any better idea to solve the problem? Many thanks for the help!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 19:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/229874#M54433</guid>
      <dc:creator>jenny_li</dc:creator>
      <dc:date>2015-10-14T19:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Select samples using proc surveyselect with certainty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/229893#M54435</link>
      <description>&lt;P&gt;Do you all the 100 + 10 random obs.,or 10-6=4 random obs?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 13:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/229893#M54435</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-10-14T13:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Select samples using proc surveyselect with certainty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/229961#M54438</link>
      <description>&lt;P&gt;&amp;nbsp; &amp;nbsp;sample size based on proportion &amp;nbsp; &amp;nbsp;no. of 100 marks in population &amp;nbsp; &amp;nbsp; samples should be taken from &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;A: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &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; &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; 2 &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 100 marks + 3 radom&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &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; &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; 1 &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 100 marks + 2 random&lt;/P&gt;
&lt;P&gt;C: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &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; &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; 3 &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; random select 2 100 marks out of the 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually certainty sampling works good for A&amp;amp;B, but just I cannot figure out any method to tell SAS to do for C as it is now a error that certainity units exceed stratum sample size.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or any better way to solve the problem without using certainty sampling?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 18:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/229961#M54438</guid>
      <dc:creator>jenny_li</dc:creator>
      <dc:date>2015-10-14T18:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Select samples using proc surveyselect with certainty/first priority ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/230005#M54443</link>
      <description>&lt;P&gt;How about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
/* Get the proportional allocation */ 
proc surveyselect data = list out = list_alloc method = srs sampsize=10 seed = 9876;
strata class / alloc=proportional nosample;
run;

/* Substract the marks=100 from allocation */
proc sql;
create table list_select as
select 
    class, 
    max(0, SampleSize - (select sum(marks=100) from list where class=a.class)) as sampleSize
from list_alloc as a;
quit;

/* Select remaining samples */
proc surveyselect 
    data = list (where=(marks ne 100)) 
    out = list_sample 
    method = srs sampsize=list_select seed = 9876;
strata class;
run;

/* Join the marks=100 students to the random samples */
proc sql;
create table list_final_sample as
select * from list where marks=100
union all corr
select * from list_sample
order by class, name;
select * from list_final_sample;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Oct 2015 03:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/230005#M54443</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-15T03:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select samples using proc surveyselect with certainty/first priority ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/230017#M54446</link>
      <description>&lt;P&gt;Thanks for the code.&lt;/P&gt;
&lt;P&gt;But in that case, total 11 samples has been selected as all 3 100 marks samples in Class C were selected.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 06:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Select-samples-using-proc-surveyselect-with-certainty-first/m-p/230017#M54446</guid>
      <dc:creator>jenny_li</dc:creator>
      <dc:date>2015-10-15T06:33:28Z</dc:date>
    </item>
  </channel>
</rss>

