<?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 Divide data into multiple samples by groups/strata in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Divide-data-into-multiple-samples-by-groups-strata/m-p/883153#M348967</link>
    <description>&lt;P&gt;I have a data set with unique individuals and their basic demographics such as gender and age group. How can I divide the data into multiple samples with the similar distribution of demographics to the original data set?&amp;nbsp; My guess is likely to use PROC SURVEYSELECT, but not sure how to set it up.&lt;/P&gt;
&lt;P&gt;For example, there are 30 individuals in the file below with gender and age_group information. To dividual the file into four samples with similar demographic distribution to the original 30 individuals. Similarly, if there are 500 distinct individuals with 10 strata by demographics, I'd like to have 5 data sets with the same distribution as the original data. How can I achieve that? Thanks a lot!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data person_fl;&lt;BR /&gt;infile datalines truncover dsd;&lt;BR /&gt;input Person_ID gender $ age_group $9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1,F,Age 21-30&lt;BR /&gt;2,F,Age 31-40&lt;BR /&gt;3,M,Age 51-60&lt;BR /&gt;4,M,Age 41-50&lt;BR /&gt;5,F,Age 21-30&lt;BR /&gt;6,M,Age 31-40&lt;BR /&gt;7,F,Age 51-60&lt;BR /&gt;8,F,Age 41-50&lt;BR /&gt;9,F,Age 21-30&lt;BR /&gt;10,M,Age 31-40&lt;BR /&gt;11,M,Age 51-60&lt;BR /&gt;12,F,Age 41-50&lt;BR /&gt;13,M,Age 21-30&lt;BR /&gt;14,F,Age 31-40&lt;BR /&gt;15,F,Age 51-60&lt;BR /&gt;16,F,Age 41-50&lt;BR /&gt;17,M,Age 21-30&lt;BR /&gt;18,M,Age 31-40&lt;BR /&gt;19,F,Age 51-60&lt;BR /&gt;20,M,Age 41-50&lt;BR /&gt;21,F,Age 21-30&lt;BR /&gt;22,F,Age 31-40&lt;BR /&gt;23,M,Age 51-60&lt;BR /&gt;24,M,Age 41-50&lt;BR /&gt;25,F,Age 21-30&lt;BR /&gt;26,M,Age 31-40&lt;BR /&gt;27,F,Age 51-60&lt;BR /&gt;28,F,Age 41-50&lt;BR /&gt;29,M,Age 21-30&lt;BR /&gt;30,M,Age 31-40&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc freq data=person_fl;&lt;BR /&gt;table gender*age_group/list missing;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jun 2023 17:35:47 GMT</pubDate>
    <dc:creator>lichee</dc:creator>
    <dc:date>2023-06-30T17:35:47Z</dc:date>
    <item>
      <title>Divide data into multiple samples by groups/strata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-data-into-multiple-samples-by-groups-strata/m-p/883153#M348967</link>
      <description>&lt;P&gt;I have a data set with unique individuals and their basic demographics such as gender and age group. How can I divide the data into multiple samples with the similar distribution of demographics to the original data set?&amp;nbsp; My guess is likely to use PROC SURVEYSELECT, but not sure how to set it up.&lt;/P&gt;
&lt;P&gt;For example, there are 30 individuals in the file below with gender and age_group information. To dividual the file into four samples with similar demographic distribution to the original 30 individuals. Similarly, if there are 500 distinct individuals with 10 strata by demographics, I'd like to have 5 data sets with the same distribution as the original data. How can I achieve that? Thanks a lot!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data person_fl;&lt;BR /&gt;infile datalines truncover dsd;&lt;BR /&gt;input Person_ID gender $ age_group $9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1,F,Age 21-30&lt;BR /&gt;2,F,Age 31-40&lt;BR /&gt;3,M,Age 51-60&lt;BR /&gt;4,M,Age 41-50&lt;BR /&gt;5,F,Age 21-30&lt;BR /&gt;6,M,Age 31-40&lt;BR /&gt;7,F,Age 51-60&lt;BR /&gt;8,F,Age 41-50&lt;BR /&gt;9,F,Age 21-30&lt;BR /&gt;10,M,Age 31-40&lt;BR /&gt;11,M,Age 51-60&lt;BR /&gt;12,F,Age 41-50&lt;BR /&gt;13,M,Age 21-30&lt;BR /&gt;14,F,Age 31-40&lt;BR /&gt;15,F,Age 51-60&lt;BR /&gt;16,F,Age 41-50&lt;BR /&gt;17,M,Age 21-30&lt;BR /&gt;18,M,Age 31-40&lt;BR /&gt;19,F,Age 51-60&lt;BR /&gt;20,M,Age 41-50&lt;BR /&gt;21,F,Age 21-30&lt;BR /&gt;22,F,Age 31-40&lt;BR /&gt;23,M,Age 51-60&lt;BR /&gt;24,M,Age 41-50&lt;BR /&gt;25,F,Age 21-30&lt;BR /&gt;26,M,Age 31-40&lt;BR /&gt;27,F,Age 51-60&lt;BR /&gt;28,F,Age 41-50&lt;BR /&gt;29,M,Age 21-30&lt;BR /&gt;30,M,Age 31-40&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc freq data=person_fl;&lt;BR /&gt;table gender*age_group/list missing;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 17:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-data-into-multiple-samples-by-groups-strata/m-p/883153#M348967</guid>
      <dc:creator>lichee</dc:creator>
      <dc:date>2023-06-30T17:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Divide data into multiple samples by groups/strata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-data-into-multiple-samples-by-groups-strata/m-p/883155#M348968</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430334"&gt;@lichee&lt;/a&gt;, you're right PROC SURVEYSELECT will do the trick here with the GROUPS=&lt;EM&gt;n&lt;/EM&gt; option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First you'll want to make sure the data is sorted by the variables that will define your strata.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=person_fl out=sorted;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;   by gender age_group;&lt;/FONT&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use PROC SURVEYSELECT using the GROUPS=&lt;EM&gt;n&lt;/EM&gt; option and the STRATA statement.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyselect data=sorted &lt;FONT color="#FF0000"&gt;groups=4&lt;/FONT&gt; out=sampled;
&lt;FONT color="#FF0000"&gt;   strata gender age_group;
&lt;/FONT&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll want to be careful and choose a number for groups no bigger than the number of observations in the smallest stratum, otherwise this will throw an error. I tried running this with GROUPS=4 on your sample dataset and got an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the documention explaining the GROUPS option:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectgroups" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectgroups&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 18:05:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-data-into-multiple-samples-by-groups-strata/m-p/883155#M348968</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2023-06-30T18:05:43Z</dc:date>
    </item>
  </channel>
</rss>

