<?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: Random Drawing using Surveyselect - no duplicate winners in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854891#M337893</link>
    <description>&lt;P&gt;So let's say for a certain department, person A has two entries, and person B and C each have 1 entry. This means that person A should have a 50% chance of getting picked, while B and C each have a 25% chance of getting picked. So, you do sampling without replacement on a data set where person A appears once but has a 50% chance of getting picked. And after person A gets picked, he shouldn't get picked again, which happens with sampling without replacement. This is METHOD=PPS (which stands for Probability Proportional to Size).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectmethod" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectmethod&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jan 2023 19:00:01 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-01-20T19:00:01Z</dc:date>
    <item>
      <title>Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854877#M337883</link>
      <description>&lt;P&gt;I'm trying to use proc surveyselect to conduct a random drawing. Entrants can have multiple entries, and I have a table that lists each entry. The problem is I'm getting duplicate winners because of the multiple entries. Is there a way to exclude duplicate observations by a certain column (Entrant_ID in this case)?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider this data set, but in actuality I have 100 dept names, and about 3,000 entrant IDs (most of which are duplicates. There are really about 90 unique entrant IDs per Dept Name. Entrant ID's will not duplicate over different dept's). Also, I will have a different actual sampsize for each dept, but I understand there is a way to make that reference a separate table, so I will be looking to do that.&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Dept_Name&lt;/TD&gt;&lt;TD&gt;Entrant_ID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 1&lt;/TD&gt;&lt;TD&gt;JRTHAL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 1&lt;/TD&gt;&lt;TD&gt;TLSMIT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 1&lt;/TD&gt;&lt;TD&gt;JRTHAL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 1&lt;/TD&gt;&lt;TD&gt;VLNEW&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 2&lt;/TD&gt;&lt;TD&gt;MRREL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 2&lt;/TD&gt;&lt;TD&gt;MNJON&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 2&lt;/TD&gt;&lt;TD&gt;MRREL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 2&lt;/TD&gt;&lt;TD&gt;MNJON&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 2&lt;/TD&gt;&lt;TD&gt;NWCON&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 3&lt;/TD&gt;&lt;TD&gt;JRMCC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 3&lt;/TD&gt;&lt;TD&gt;ADLON&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 3&lt;/TD&gt;&lt;TD&gt;JRMCC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 3&lt;/TD&gt;&lt;TD&gt;ADLON&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 3&lt;/TD&gt;&lt;TD&gt;BFPIT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dept 3&lt;/TD&gt;&lt;TD&gt;BFPIT&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Code I am using:&lt;/P&gt;&lt;P&gt;proc surveyselect data=work.random_draw_entries out=all_winners method=srs reps=1 sampsize=10;&lt;BR /&gt;strata dept_name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I'm not tied to using surveyselect, and I have many ways to manipulate the data if you have suggestions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 17:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854877#M337883</guid>
      <dc:creator>Jay_210</dc:creator>
      <dc:date>2023-01-20T17:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854889#M337891</link>
      <description>&lt;P&gt;It sounds like you want random sample without replacement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First you need to remove any duplicate Entrant_ID values. Then, in PROC SURVEYSELECT use METHOD=SRS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There should not be a need to use a different data set for each department, use the STRATA statement to have each department sampled properly.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 18:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854889#M337891</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-20T18:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854890#M337892</link>
      <description>I can't remove the duplicate entrant ID values because that would eliminate their multiple entries. Each line in the data set is sort of like their "raffle ticket" so if I remove any it removes their multiple "raffle tickets." I'm already using SRS, but the "without replacement" feature is going line by line. I need it to go Entrant ID by Entrant ID. I hope that makes sense.</description>
      <pubDate>Fri, 20 Jan 2023 18:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854890#M337892</guid>
      <dc:creator>Jay_210</dc:creator>
      <dc:date>2023-01-20T18:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854891#M337893</link>
      <description>&lt;P&gt;So let's say for a certain department, person A has two entries, and person B and C each have 1 entry. This means that person A should have a 50% chance of getting picked, while B and C each have a 25% chance of getting picked. So, you do sampling without replacement on a data set where person A appears once but has a 50% chance of getting picked. And after person A gets picked, he shouldn't get picked again, which happens with sampling without replacement. This is METHOD=PPS (which stands for Probability Proportional to Size).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectmethod" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectmethod&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 19:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854891#M337893</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-20T19:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854892#M337894</link>
      <description>&lt;P&gt;Lets discuss the easy bit first. When you have stratified data, such as your Dept_name variable, you can specify a separate samplesize for each strata directly, though with 100 departments it may be easier to use Samprate, such as .1 to get 10% of each strata. If you want to specify a specific sample size for each strata you have two basic approaches. Use the Sampsize option with a list. Coonsider this code:&lt;/P&gt;
&lt;PRE&gt;proc surveyselect data=work.random_draw_entries out=all_winners method=srs reps=1 sampsize= (2 1 4);
   strata dept_name;
run;&lt;/PRE&gt;
&lt;P&gt;IF there are exactly 3 strata values, then the first strata in the sort order would select 2 records, the second would select 1 and the third strata would have 4 records.&lt;/P&gt;
&lt;P&gt;With 100 or so strata that gets a bit ugly to type on a line of code. You can use the Sampsize=datasetname to provide a data set with the strata variables and the number of records to select from each strata. The desired sample size variable must be named one of _nsize_ or SampleSize.&lt;/P&gt;
&lt;PRE&gt;data deptsampsize;
   input dept_name $ _nsize_;
datalines;
Dept1   2
Dept2   1
Dept3   4
;

proc surveyselect data=work.random_draw_entries out=all_winners method=srs reps=1 sampsize=deptsampsize;
strata dept_name;
run;&lt;/PRE&gt;
&lt;P&gt;A similar approach is available if you want different sampling rates for each strata. If using the SAMPRATE=dataset option the variable name holding the desired sample rate is named _rate_ and can be range of 1-100 (treated 1% to 100%) or 0.01 to 1.&lt;/P&gt;
&lt;P&gt;Now for a more complicated bit of how to treat multiple entries. Do you want each person to have a better chance of selection if they have more entries? Then you might consider summarizing your data to get a count of entries per Dept Entrant and use that as the input data set to Proc suryvey select indicating that count a Size variable and use one of the selection methods like PPS.&lt;/P&gt;
&lt;P&gt;Easy to create such as summary set for use.&lt;/P&gt;
&lt;PRE&gt;Proc summary data=have nway;
   class dept_name entrant_id;
   output out=entrysummary (drop=_type_);
run;
/* will have a variable _freq_ that counts how many time the combination appears*/

Proc surveyselect data=entrysummary method=PPS 
   samprate= .1 out=all_winners;
   strata Dept_name;
   size _freq_;
run;&lt;/PRE&gt;
&lt;P&gt;There are multiple PPS methods, read the documentation to see if one of them fits your needs better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are ways around the summary step for some data but I find this clearer to use and I think for your purpose it will be much cleaner output. You might consider providing the SEED option on the Proc statement. That way you can recreate the same output given the same input when using the same SAS version (no guarantee of same result in different versions and in some cases different computers).&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 19:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854892#M337894</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-20T19:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854975#M337931</link>
      <description>You could use PROC SORT to remove these duplicated value ,&lt;BR /&gt;proc sort data=have out=want nodupkey;by Entrant_ID;run;&lt;BR /&gt;After that running PROC SURVEYSELECT .</description>
      <pubDate>Sat, 21 Jan 2023 14:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/854975#M337931</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-21T14:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855166#M338008</link>
      <description>&lt;P&gt;I need to keep the duplicates in the file that I do the survey select on because those are entries in the drawing. It gives them a better chance of getting picked. What I'm trying to figure out is how to make it non select an entrant after they have already been selected (based on entrant_id).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 18:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855166#M338008</guid>
      <dc:creator>Jay_210</dc:creator>
      <dc:date>2023-01-23T18:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855194#M338018</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438662"&gt;@Jay_210&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to keep the duplicates in the file that I do the survey select on because those are entries in the drawing. It gives them a better chance of getting picked. What I'm trying to figure out is how to make it non select an entrant after they have already been selected (based on entrant_id).&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Have you read my post about PPS and summary data to select?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 19:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855194#M338018</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-23T19:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855209#M338031</link>
      <description>I have, yes. I was going to reply but I still need to look into the PPS options for better understanding. I do have a list of entrant_ids and the number of entries they have. I was under the impression that wouldn't work for PPS by strata, but if I was wrong, it might work for me.</description>
      <pubDate>Mon, 23 Jan 2023 20:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855209#M338031</guid>
      <dc:creator>Jay_210</dc:creator>
      <dc:date>2023-01-23T20:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855213#M338033</link>
      <description>&lt;P&gt;To select entrants (unique entrants) in proportion to their number of entries, you can use PROC SURVEYSELECT with the PPS option in the CLUSTER statement, like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CLUSTER entrant_id / PPS;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Documentation is &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_035/statug/statug_surveyselect_syntax05.htm" target="_self"&gt;here&lt;/A&gt;. The PPS option in the CLUSTER statement automatically computes the cluster (entrant_id) size measure as the number of observations (entries) in the cluster.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 20:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855213#M338033</guid>
      <dc:creator>Watts</dc:creator>
      <dc:date>2023-01-23T20:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855274#M338054</link>
      <description>When I run this with "samprate= .1" I get an error: ERROR: The SAMPRATE= option may not be specified with METHOD=PPS. If I change it to sampsize=10 I get an error: ERROR: For METHOD=PPS, the relative size of each sampling unit must not exceed (1/SAMPSIZE).&lt;BR /&gt;&lt;BR /&gt;I do like your suggestion to use Sampsize=datasetname once I can figure this out.</description>
      <pubDate>Tue, 24 Jan 2023 00:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855274#M338054</guid>
      <dc:creator>Jay_210</dc:creator>
      <dc:date>2023-01-24T00:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Random Drawing using Surveyselect - no duplicate winners</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855275#M338055</link>
      <description>This is interesting. I do get the same errors as I replied to ballardw involving samprate/sampsize though.</description>
      <pubDate>Tue, 24 Jan 2023 00:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-Drawing-using-Surveyselect-no-duplicate-winners/m-p/855275#M338055</guid>
      <dc:creator>Jay_210</dc:creator>
      <dc:date>2023-01-24T00:55:43Z</dc:date>
    </item>
  </channel>
</rss>

