<?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: How to get a cluster sample with replacement in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/How-to-get-a-cluster-sample-with-replacement/m-p/423905#M4231</link>
    <description>&lt;P&gt;From the VeryOldSASGuy101 Course notes, here is an approach that pre-dates SURVEYSELECT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, create a SAS data set with ID only, and one observation per ID.&amp;nbsp; Then design your samples.&amp;nbsp; For example, if you want 100 samples, each with 50 subjects (with replacement):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=longitudinal_data (keep=ID) out=unique_IDs nodupkey;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data sample_IDs;&lt;/P&gt;
&lt;P&gt;do iteration = 1 to 100;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do subject = 1 to 50;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; obsno = ceil(ranuni(12345) * _nobs_);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set unique_IDs point=obsno obs=_nobs_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=sample_IDs;&lt;/P&gt;
&lt;P&gt;tables iteration * ID / noprint out=sample_map (keep=iteration ID count);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This doesn't give you the sampled data.&amp;nbsp; Rather, it gives you a list of which subjects to select, and how many times to select each, for each of 100 iterations ... all randomly sampled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point, you might be ready for a macro that selects each sample and runs it through the hoops that you describe as a series of DATA and PROC steps.&amp;nbsp; Here's the idea without a macro, to select iteration #5:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=longitudinal_data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by ID;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data sample5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; merge longitudinal_data sample_map (where=(iteration=5) in=selected);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if selected;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do _n_=1 to count;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on the nature of your intended processing, there might be ways to use a BY statement instead of extracting each sample separately.&amp;nbsp; But we would need to know more of the downstream processing logic to consider that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write back if you have questions, or need help converting the logic to a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Dec 2017 14:59:05 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-12-28T14:59:05Z</dc:date>
    <item>
      <title>How to get a cluster sample with replacement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-get-a-cluster-sample-with-replacement/m-p/423900#M4230</link>
      <description>&lt;P&gt;I have a dataset with a natural hierarchy; observations within subjects. I wish to draw samples from this dataset using sampling at the subject level with replacement. My first So I decided to roll my own. I got all the bits working and tried to stitch everything together in a macro (some bits were data steps, some procedures) when I realized this was a dead end without being able to nest both datasets and procedures within a control loop in the highest level datastep (or macro). The procedures needed to execute and then return control to the macro. This led me to discover proc&amp;nbsp; FCMP which appeared to do exactly what I needed but seemed like a difficult approach. The following is a pseudocode description of what I was trying to do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;N =&amp;nbsp;the number of subjects in the longitudinal dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; iterate over N&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use surveyselect to randomly draw a subject ID (with replacement)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create a small dataset consisting of only the one subject and all the observations on said subject&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; paste that dataset onto a growing dataset of observations (not all unique in subject id)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; use this dataset in another program (repeat many times)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm starting to think there must be a better way. Any help much appreciated using SAS 9.3&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 13:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-get-a-cluster-sample-with-replacement/m-p/423900#M4230</guid>
      <dc:creator>OldSASGuy100</dc:creator>
      <dc:date>2017-12-28T13:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a cluster sample with replacement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-get-a-cluster-sample-with-replacement/m-p/423905#M4231</link>
      <description>&lt;P&gt;From the VeryOldSASGuy101 Course notes, here is an approach that pre-dates SURVEYSELECT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, create a SAS data set with ID only, and one observation per ID.&amp;nbsp; Then design your samples.&amp;nbsp; For example, if you want 100 samples, each with 50 subjects (with replacement):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=longitudinal_data (keep=ID) out=unique_IDs nodupkey;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data sample_IDs;&lt;/P&gt;
&lt;P&gt;do iteration = 1 to 100;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do subject = 1 to 50;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; obsno = ceil(ranuni(12345) * _nobs_);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set unique_IDs point=obsno obs=_nobs_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=sample_IDs;&lt;/P&gt;
&lt;P&gt;tables iteration * ID / noprint out=sample_map (keep=iteration ID count);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This doesn't give you the sampled data.&amp;nbsp; Rather, it gives you a list of which subjects to select, and how many times to select each, for each of 100 iterations ... all randomly sampled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point, you might be ready for a macro that selects each sample and runs it through the hoops that you describe as a series of DATA and PROC steps.&amp;nbsp; Here's the idea without a macro, to select iteration #5:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=longitudinal_data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by ID;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data sample5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; merge longitudinal_data sample_map (where=(iteration=5) in=selected);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if selected;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do _n_=1 to count;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on the nature of your intended processing, there might be ways to use a BY statement instead of extracting each sample separately.&amp;nbsp; But we would need to know more of the downstream processing logic to consider that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write back if you have questions, or need help converting the logic to a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 14:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-get-a-cluster-sample-with-replacement/m-p/423905#M4231</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-28T14:59:05Z</dc:date>
    </item>
  </channel>
</rss>

