<?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 random samples with conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839952#M332101</link>
    <description>I have already checked how big is the population, which is much more big than 18, that’s why I don’t know how to correct till it works.</description>
    <pubDate>Fri, 21 Oct 2022 15:27:52 GMT</pubDate>
    <dc:creator>ZhihanZhou</dc:creator>
    <dc:date>2022-10-21T15:27:52Z</dc:date>
    <item>
      <title>select random samples with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839950#M332099</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;i want to select 87 samples with following conditions and put all these selected samples into one file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if hz='1-7' and zweck=1 then group=1;&lt;BR /&gt;else if hz='1-7' and zweck=7 then group=2;&lt;BR /&gt;else if hz='3-7' and zweck=3 then group=3;&lt;BR /&gt;else if hz='3-7' and zweck=7 then group=4;&lt;BR /&gt;else if hz='4-7' and zweck=7 then group=5;&lt;BR /&gt;else if hz='5-7' and zweck=7 then group=6;&lt;BR /&gt;else if hz='6-7' and zweck=7 then group=7;&lt;BR /&gt;else if hz='10-7' and zweck=7 then group=8;&lt;BR /&gt;run;&lt;BR /&gt;proc surveyselect data=want&lt;BR /&gt;method=srs n=87 out=want1 sampsize=(18 6 17 4 10 20 5 7);&lt;BR /&gt;strata group;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which means, 18 samples from group1, 6 from group2 and so on ......&lt;/P&gt;&lt;P&gt;but it didn't work and comes this warning, but i have already checked the group1 is much more bigger than 7. Could you help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZhihanZhou_1-1666364862200.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76441i4A5589946D6F29BE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZhihanZhou_1-1666364862200.png" alt="ZhihanZhou_1-1666364862200.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best wishes,&lt;/P&gt;&lt;P&gt;Zhihan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839950#M332099</guid>
      <dc:creator>ZhihanZhou</dc:creator>
      <dc:date>2022-10-21T15:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: select random samples with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839951#M332100</link>
      <description>&lt;P&gt;You are trying to select a random sample of size 18 from a population that has 7 items. This can't be done.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839951#M332100</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-21T15:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: select random samples with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839952#M332101</link>
      <description>I have already checked how big is the population, which is much more big than 18, that’s why I don’t know how to correct till it works.</description>
      <pubDate>Fri, 21 Oct 2022 15:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839952#M332101</guid>
      <dc:creator>ZhihanZhou</dc:creator>
      <dc:date>2022-10-21T15:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: select random samples with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839960#M332106</link>
      <description>&lt;P&gt;Okay, then read the next error message ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data is not sorted properly.&lt;/P&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/432939"&gt;@ZhihanZhou&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have already checked how big is the population, which is much more big than 18, that’s why I don’t know how to correct till it works.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;From now on, it would be helpful if you state all the information you have about the problem in your initial message, rather than withholding information about what you have already done.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839960#M332106</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-21T15:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: select random samples with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839965#M332109</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432939"&gt;@ZhihanZhou&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You must exclude the (seven) observations with missing GROUP values as these would form the first stratum otherwise: Add a WHERE statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where group&amp;gt;.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to the PROC SURVEYSELECT step, e.g., before the STRATA statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If dataset WANT is not yet sorted by GROUP, you need to sort it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=want;
by group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would also replace the &lt;FONT face="courier new,courier"&gt;n=&lt;/FONT&gt; option by a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectseed" target="_blank" rel="noopener"&gt;SEED=&lt;/A&gt; option to specify a random seed so that you can reproduce the sample. SAS ignores the &lt;FONT face="courier new,courier"&gt;n=87&lt;/FONT&gt; anyway because you provide stratum sample sizes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, if the error "&lt;FONT face="courier new,courier"&gt;sample size ... greater than the number of sampling units&lt;/FONT&gt;" still occurs, you can add the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectselectall" target="_blank" rel="noopener"&gt;SELECTALL&lt;/A&gt; option to the PROC SURVEYSELECT statement. Instead of error messages you will then get notes in the log about strata with a smaller sample size than what you specified.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 16:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839965#M332109</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-10-21T16:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: select random samples with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839974#M332112</link>
      <description>&lt;P&gt;Hello FreelanceReinhard,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks very much for your reply!&amp;nbsp;&lt;/P&gt;&lt;P&gt;i've tried your code besides created a new file, which only has 'group ne .', and it works right now so great, just is what i want!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if hz='1-7' and zweck=1 then group=1;&lt;BR /&gt;if hz='1-7' and zweck=7 then group=2;&lt;BR /&gt;if hz='3-7' and zweck=3 then group=3;&lt;BR /&gt;if hz='3-7' and zweck=7 then group=4;&lt;BR /&gt;if hz='4-7' and zweck=7 then group=5;&lt;BR /&gt;if hz='5-7' and zweck=7 then group=6;&lt;BR /&gt;if hz='6-7' and zweck=7 then group=7;&lt;BR /&gt;if hz='10-7' and zweck=7 then group=8;&lt;BR /&gt;run;&lt;BR /&gt;data want1;&lt;BR /&gt;set want;&lt;BR /&gt;where group ne .;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=want1;&lt;BR /&gt;by group;&lt;BR /&gt;run;&lt;BR /&gt;proc surveyselect data=1&lt;BR /&gt;method=srs sampsize=(18 6 17 4 10 20 5 7) selectall out=want2;&lt;BR /&gt;strata group;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 16:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839974#M332112</guid>
      <dc:creator>ZhihanZhou</dc:creator>
      <dc:date>2022-10-21T16:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: select random samples with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839977#M332114</link>
      <description>Thanks for your reply!&lt;BR /&gt;I’ve solved the problem:)</description>
      <pubDate>Fri, 21 Oct 2022 16:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-random-samples-with-conditions/m-p/839977#M332114</guid>
      <dc:creator>ZhihanZhou</dc:creator>
      <dc:date>2022-10-21T16:44:17Z</dc:date>
    </item>
  </channel>
</rss>

