<?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 Creating a random Sample under constraint in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-a-random-Sample-under-constraint/m-p/646127#M31003</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I need to create a stratified sample starting from a wider population. But in creating the sample I have the constraint that I can choose observations only on a subset of the entire population. However, at the end the stratification variables should reflect the same proportions of the whole population and not of the population subset. I hope I explained.&lt;/P&gt;&lt;P&gt;I have tried to use the proc surveyselect with the where condition but the final proportions don't reflect the whole population.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc surveyselect data=pop_new_14_17_stima (where=(FLAG_INVIO_BFD=1)) method=sys rate=0.9&lt;BR /&gt;seed=1953 out=camp_new rep=1 ;&lt;BR /&gt;strata DAT_FINE_PERIO tipo_cli_ps DEFAULT;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 08 May 2020 08:09:36 GMT</pubDate>
    <dc:creator>fedeava</dc:creator>
    <dc:date>2020-05-08T08:09:36Z</dc:date>
    <item>
      <title>Creating a random Sample under constraint</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-a-random-Sample-under-constraint/m-p/646127#M31003</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I need to create a stratified sample starting from a wider population. But in creating the sample I have the constraint that I can choose observations only on a subset of the entire population. However, at the end the stratification variables should reflect the same proportions of the whole population and not of the population subset. I hope I explained.&lt;/P&gt;&lt;P&gt;I have tried to use the proc surveyselect with the where condition but the final proportions don't reflect the whole population.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc surveyselect data=pop_new_14_17_stima (where=(FLAG_INVIO_BFD=1)) method=sys rate=0.9&lt;BR /&gt;seed=1953 out=camp_new rep=1 ;&lt;BR /&gt;strata DAT_FINE_PERIO tipo_cli_ps DEFAULT;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 08:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-a-random-Sample-under-constraint/m-p/646127#M31003</guid>
      <dc:creator>fedeava</dc:creator>
      <dc:date>2020-05-08T08:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a random Sample under constraint</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-a-random-Sample-under-constraint/m-p/646154#M31006</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327801"&gt;@fedeava&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the ALLOC= option of the &lt;A href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_surveyselect_syntax07.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_blank" rel="noopener"&gt;STRATA statement&lt;/A&gt; is suitable for this purpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example:&lt;/P&gt;
&lt;P&gt;Let's say we want to draw an 80% sample (without replacement) from SASHELP.HEART, restricted to non-smokers (n=2501, selection criterion: &lt;FONT face="courier new,courier"&gt;smoking_status=:'N'&lt;/FONT&gt;), but strive for a distribution of blood pressure status (&lt;FONT face="courier new,courier"&gt;BP_Status&lt;/FONT&gt;) as in the unrestricted dataset, i.e. (PROC FREQ output):&lt;/P&gt;
&lt;PRE&gt;                    Blood Pressure Status

                                      Cumulative    Cumulative
BP_Status    Frequency     Percent     Frequency      Percent
--------------------------------------------------------------
High             2267       43.52          2267        43.52
Normal           2143       41.14          4410        84.66
Optimal           799       15.34          5209       100.00&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Store stratum allocation proportions in a dataset STRATA */

proc freq data=sashelp.heart noprint;
tables bp_status / out=strata(drop=count rename=(percent=_alloc_));
run;

/* Select the subset (input dataset for PROC SURVEYSELECT) */

proc sort data=sashelp.heart out=restrpop;
where smoking_status=:'N';
by bp_status;
run;

/* Draw the random sample */

proc surveyselect data=restrpop
method=srs rate=0.8
seed=2718 out=want;
strata bp_status / alloc=strata;
run;

/* Check distribution of BP_Status */

proc freq data=want;
tables bp_status;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                    Blood Pressure Status

                                      Cumulative    Cumulative
BP_Status    Frequency     Percent     Frequency      Percent
--------------------------------------------------------------
High              871       43.53           871        43.53
Normal            823       41.13          1694        84.66
Optimal           307       15.34          2001       100.00&lt;/PRE&gt;
&lt;P&gt;Note that, e.g., with rate=0.9 the stratum sample size for stratum &lt;FONT face="courier new,courier"&gt;BP_Status='Optimal'&lt;/FONT&gt; would (necessarily) be capped at the stratum total, leading to not strictly proportional sample size allocation (see notes in the SAS log in this case).&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 11:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-a-random-Sample-under-constraint/m-p/646154#M31006</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-05-08T11:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a random Sample under constraint</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-a-random-Sample-under-constraint/m-p/646195#M31008</link>
      <description>&lt;P&gt;Wonderful!&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This was exactly the help I was looking for. I was able to create a stratified sample on 3 drivers.... I'll probably have to add further drivers... I hope it continues to perform..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 13:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-a-random-Sample-under-constraint/m-p/646195#M31008</guid>
      <dc:creator>fedeava</dc:creator>
      <dc:date>2020-05-08T13:16:33Z</dc:date>
    </item>
  </channel>
</rss>

