<?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 How to select specific random entries based on if condition? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784247#M250241</link>
    <description>&lt;P&gt;I have customers data along with their occupation, now instead of taking a random sample from the whole base I just want to randomly select specific customers from a &amp;nbsp;specific occupation and keep the customers from other occupations as it is in the output table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the data, I have 1 lac customers working in the private sector, and the count of customers from other occupations is less than 10 thousand. Now I want to randomly select only 10 thousand customers from the private sector and want to keep the customers from other occupations as it is in the output data&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 07:47:37 GMT</pubDate>
    <dc:creator>Saurabh_Rana</dc:creator>
    <dc:date>2021-12-06T07:47:37Z</dc:date>
    <item>
      <title>How to select specific random entries based on if condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784247#M250241</link>
      <description>&lt;P&gt;I have customers data along with their occupation, now instead of taking a random sample from the whole base I just want to randomly select specific customers from a &amp;nbsp;specific occupation and keep the customers from other occupations as it is in the output table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the data, I have 1 lac customers working in the private sector, and the count of customers from other occupations is less than 10 thousand. Now I want to randomly select only 10 thousand customers from the private sector and want to keep the customers from other occupations as it is in the output data&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 07:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784247#M250241</guid>
      <dc:creator>Saurabh_Rana</dc:creator>
      <dc:date>2021-12-06T07:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to select specific random entries based on if condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784257#M250244</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316224"&gt;@Saurabh_Rana&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/statug/15.2/statug_surveyselect_overview.htm" target="_blank" rel="noopener nofollow noreferrer"&gt;PROC SURVEYSELECT&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;with the &lt;A href="https://documentation.sas.com/doc/en/statug/15.2/statug_surveyselect_syntax01.htm#statug.surveyselect.selectselectall" target="_blank" rel="noopener"&gt;SELECTALL option&lt;/A&gt; and a&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://documentation.sas.com/doc/en/statug/15.2/statug_surveyselect_syntax07.htm" target="_blank" rel="noopener nofollow noreferrer"&gt;STRATA statement&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;(like &lt;FONT face="courier new,courier"&gt;STRATA occupation;&lt;/FONT&gt;) and then specify, e.g., &lt;FONT face="courier new,courier"&gt;n=10000&lt;/FONT&gt; as the sample size. This will draw random samples of 10,000 observations (customers) per occupation if possible and select all observations from smaller strata (with &amp;lt;=10,000 observations). Or specify individual sample sizes for each stratum. With the SELECTALL option it doesn't hurt if some of the sample sizes are actually too large.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create example dataset, sorted by stratum (here: age group) */

proc sort data=sashelp.class out=class;
by age;
run; /* Six age groups (strata): 11, 12, ..., 16. */

/* If possible, select 3 randomly from each group, else select all */

proc surveyselect data=class
method=srs n=3 selectall
seed=2718 out=samp;
strata age;
run;

/* Example with individual sample sizes for each of the six strata */

proc surveyselect data=class
method=srs n=(2 1 4 4 3 2) selectall
seed=2718 out=samp2;
strata age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Compare PROC FREQ results (&lt;FONT face="courier new,courier"&gt;tables age;&lt;/FONT&gt;) for CLASS, SAMP and SAMP2 to see the effect of the N= and SELECTALL options.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 09:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784257#M250244</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-12-06T09:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to select specific random entries based on if condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784508#M250372</link>
      <description>What if instead of capping the max sample count, I want to define the max proportion percentage. Basically, can I define the maximum allowed proportion any occupation can have?</description>
      <pubDate>Tue, 07 Dec 2021 11:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784508#M250372</guid>
      <dc:creator>Saurabh_Rana</dc:creator>
      <dc:date>2021-12-07T11:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to select specific random entries based on if condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784515#M250374</link>
      <description>&lt;P&gt;You can specify target percentages for each stratum in the &lt;A href="https://documentation.sas.com/doc/en/statug/15.2/statug_surveyselect_syntax07.htm#statug.surveyselect.alloclist" target="_blank" rel="noopener"&gt;ALLOC= option&lt;/A&gt; of the STRATA statement (either as a list of values or in the form of a dataset).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example (continuing my previous post)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyselect data=class
method=srs n=10
seed=2718 out=samp;
strata age / alloc=(10 20 20 20 20 10);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This requests proportions of 10%, 20%, ..., 10% for the six age groups 11, 12, ..., 16 with a total sample size of n=10. (Instead of percentages 10, 20, ... you may write proportions like 0.1, 0.2, ... in the list. The sum must be 100 or 1, respectively, up to a little rounding error as in 0.167 for 1/6.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note, however, that the numbers in the list cannot always be attained exactly (e.g., because the sample size of a stratum is necessarily an integer and cannot be greater than the size of the stratum). This includes cases where the actual proportion of a stratum exceeds the corresponding allocated proportion. Change &lt;FONT face="courier new,courier"&gt;n=10&lt;/FONT&gt; to &lt;FONT face="courier new,courier"&gt;n=11&lt;/FONT&gt; in the code above to see such an example. But if you specify realistic proportions (based on your knowledge of the stratum sizes), the result should be satisfactory.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 13:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-specific-random-entries-based-on-if-condition/m-p/784515#M250374</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-12-07T13:06:27Z</dc:date>
    </item>
  </channel>
</rss>

