<?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 create a Random Sample using SAS EG in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-a-Random-Sample-using-SAS-EG/m-p/490601#M31636</link>
    <description>&lt;P&gt;It would be possible using a bit of a brute force programming approach: i) figure out how many are missing for a stratum, ii) generate the code to select from the required alternate stratum, iii) macrofy it to handle all of the strata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm hoping that someone more familiar with the statistics side will come to the rescue with a smart idea, otherwise I'll try to mock something up for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try posting this in one of the statistical forums, you might catch the eye of the right person.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
    <pubDate>Tue, 28 Aug 2018 19:47:40 GMT</pubDate>
    <dc:creator>TomKari</dc:creator>
    <dc:date>2018-08-28T19:47:40Z</dc:date>
    <item>
      <title>How to create a Random Sample using SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-a-Random-Sample-using-SAS-EG/m-p/490547#M31630</link>
      <description>&lt;P&gt;I would like to create a Random Sample using SAS EG.&amp;nbsp;I have over 3,000 records split across 7 locations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At these locations I have 2 different programs ('ALPHA' and 'BETA'&amp;nbsp;) and I would like to have a random sample of 50 records for each location and each program. The EG wizard&amp;nbsp;accomplishes this fairly easily with the following code, but I encounter the issue outlined further in the details below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* -------------------------------------------------------------------&lt;BR /&gt;Code generated by SAS Task&lt;/P&gt;&lt;P&gt;Generated on: Tuesday, August 28, 2018 at 11:09:15 AM&lt;BR /&gt;By task: Random Sample&lt;/P&gt;&lt;P&gt;Input data: SASApp:WORK.PROG_BY_LOCATION&lt;BR /&gt;Server: SASApp&lt;BR /&gt;------------------------------------------------------------------- */&lt;BR /&gt;TITLE; FOOTNOTE;&lt;/P&gt;&lt;P&gt;%_eg_conditional_dropds(WORK.SORTTempTableSorted, "%STR(WORK.RANDRandomSamplePROG_BY_LOCAT)"n);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SORT&lt;BR /&gt;DATA=WORK.PROG_BY_LOCATION()&lt;BR /&gt;OUT=WORK.SORTTempTableSorted;&lt;BR /&gt;BY LOCATION PROGRAM;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SURVEYSELECT DATA=WORK.SORTTempTableSorted&lt;BR /&gt;OUT=WORK.RANDRandomSamplePROG_BY_LOCAT&lt;BR /&gt;METHOD=SRS&lt;BR /&gt;N=50&lt;BR /&gt;NOPRINT&lt;BR /&gt;SELECTALL;&lt;BR /&gt;STRATA LOCATION PROGRAM;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;%_eg_conditional_dropds(WORK.SORTTempTableSorted);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately when I look at my data I see that I have 5 locations that do not have 50 records associated with the 'BETA' program (see below). I would like to&amp;nbsp;amend the code above to increase the number of records to 100 per location. I would like to keep all of the 'BETA' records in the sample, but at the five locations where there are not enough 'BETA' records I want to pull additional records from the 'ALPHA' group. I don't see a way to do this in the SAS EG Random Sample dialog box, but hoped there was a way to adjust the code above.&lt;/P&gt;&l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;/TD&gt;&lt;TD&gt;69&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;56&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;G&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;55&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;TD&gt;350&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;550&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 28 Aug 2018 16:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-a-Random-Sample-using-SAS-EG/m-p/490547#M31630</guid>
      <dc:creator>runningjay</dc:creator>
      <dc:date>2018-08-28T16:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a Random Sample using SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-a-Random-Sample-using-SAS-EG/m-p/490601#M31636</link>
      <description>&lt;P&gt;It would be possible using a bit of a brute force programming approach: i) figure out how many are missing for a stratum, ii) generate the code to select from the required alternate stratum, iii) macrofy it to handle all of the strata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm hoping that someone more familiar with the statistics side will come to the rescue with a smart idea, otherwise I'll try to mock something up for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try posting this in one of the statistical forums, you might catch the eye of the right person.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 19:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-a-Random-Sample-using-SAS-EG/m-p/490601#M31636</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-08-28T19:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a Random Sample using SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-a-Random-Sample-using-SAS-EG/m-p/490616#M31637</link>
      <description>&lt;P&gt;I am not going to suggest any "automagic" solution because the solution will require macro coding; the&amp;nbsp;code is likely to be ugly, fragile possibly subject to abuse.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the information from your proc freq output to modify the N= clause to match the data you have.&lt;/P&gt;
&lt;P&gt;I think&lt;/P&gt;
&lt;PRE&gt;n= (50 50 50 50 54 46 76 24 81 19 94 6 95 5)&lt;/PRE&gt;
&lt;P&gt;Since you have two strata variables the first n is for the first Location and first value of Program, the second is the first Location value and the 2nd program, the third is the second Location and 1st program, second location 2nd program and so forth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will at least provide appropriate selection probabilities and weighting values for the different strata sizes.&lt;/P&gt;
&lt;P&gt;Or use the information to create an appropriate SAMPSIZE data set which would have the desired sample sizes for each combination of strata variables. This set would look a lot like the n= list above.&lt;/P&gt;
&lt;PRE&gt;date work.sampsize;
   input location $ program $ sampsize;
datalines;
A Alpha 50
A Beta  50
B Alpha 50
B Beta  50
C Alpha 94
C Beta  46
D Alpha 76
D Beta  24
E Alpha 81
E Beta  19
F Alpha 94
F Beta   6
G Alpha 95
G Beta   5
;
run;&lt;/PRE&gt;
&lt;P&gt;You reference the data set name on the N= (or SAMPSIZE= ) option in the proc statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data set approach would be the easiest to create an automagic and could be done to adjust either Alpha or Beta sampsizes.&lt;/P&gt;
&lt;P&gt;But since you are using EG and the code you show looks to be pretty straight from the interface menus that might be just a bit past your experience level. This would be where one of my professors used to say "Left as an exercise for the interested reader."&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 20:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-a-Random-Sample-using-SAS-EG/m-p/490616#M31637</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-28T20:36:51Z</dc:date>
    </item>
  </channel>
</rss>

