<?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 distribution of records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Random-distribution-of-records/m-p/96943#M20442</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Compute the required sampling rates in each strata (Y and N), use surveyselect to draw the sample and use a WHERE clause to drop the strata=N from the selected sample:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;STRONG&gt;data vendor_seg;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Input ID $ 1-4 Rank $ 6;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1771 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3456 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5134 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;9087 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2829 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2749 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;9987 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3094 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2938 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;8320 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5681 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2922 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;0987 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1108 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3879 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;8734 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1930 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;4752 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5609 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;7541 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;8745 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;9109 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5904 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;7145 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;0876 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2939 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;7340 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=vendor_seg; by rank; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;create table strataRate as&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rank, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.2*sum(n)/n as _rate_&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select rank, count(*) as n from vendor_seg group by rank);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc surveyselect data=vendor_seg seed=1239&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rate=strataRate out=sample(where=(rank="Y"));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;strata rank;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 06 Jun 2013 03:01:28 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2013-06-06T03:01:28Z</dc:date>
    <item>
      <title>Random distribution of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-distribution-of-records/m-p/96942#M20441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I'm kind off stuck in a middle of a code and need some help. I have a population where it needs to be split 60/40. Then the 40% population should be evenly distributed(50/50) based on Rank variable. Any left over records after 50/50 split should be deleted. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So for example I have &lt;/P&gt;&lt;P&gt;27 total records&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;14 Records- segA&lt;/P&gt;&lt;P&gt;13 Records- SegB&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SegB population has total 13 records out of which 10 records with Rank = 'Y' and 3 records with Rank = 'N'. Now the 13 records should be evenly split based on Rank flag. Meaning Randomly select 3 accounts from Rank = 'Y' and delete the remaining 7 left over records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if i have 13 records in the segB population &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;10 - Y's&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3 - N's&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would expect to see 6 total records&lt;/P&gt;&lt;P&gt;3 Y's(remove 7 Y records randomly)&lt;/P&gt;&lt;P&gt;3 N's&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So my total final volume would be 20(14+6) records.&lt;/P&gt;&lt;P&gt;Sample data set&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data vendor_seg;&lt;/P&gt;&lt;P&gt;Infile cards;&lt;/P&gt;&lt;P&gt;Input ID $ 1-4 Rank $ 6;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1771 Y&lt;/P&gt;&lt;P&gt;3456 Y&lt;/P&gt;&lt;P&gt;5134 N&lt;/P&gt;&lt;P&gt;9087 Y&lt;/P&gt;&lt;P&gt;2829 Y&lt;/P&gt;&lt;P&gt;2749 Y&lt;/P&gt;&lt;P&gt;9987 Y&lt;/P&gt;&lt;P&gt;3094 Y&lt;/P&gt;&lt;P&gt;2938 N&lt;/P&gt;&lt;P&gt;8320 Y&lt;/P&gt;&lt;P&gt;5681 Y&lt;/P&gt;&lt;P&gt;2922 N&lt;/P&gt;&lt;P&gt;0987 Y&lt;/P&gt;&lt;P&gt;1108 N&lt;/P&gt;&lt;P&gt;3879 N&lt;/P&gt;&lt;P&gt;8734 N&lt;/P&gt;&lt;P&gt;1930 N&lt;/P&gt;&lt;P&gt;4752 Y&lt;/P&gt;&lt;P&gt;5609 N&lt;/P&gt;&lt;P&gt;7541 Y&lt;/P&gt;&lt;P&gt;8745 Y&lt;/P&gt;&lt;P&gt;9109 N&lt;/P&gt;&lt;P&gt;5904 Y&lt;/P&gt;&lt;P&gt;7145 Y&lt;/P&gt;&lt;P&gt;0876 N&lt;/P&gt;&lt;P&gt;2939 Y&lt;/P&gt;&lt;P&gt;7340 Y&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data vendor_seg2;&lt;/P&gt;&lt;P&gt;Set vendor_seg;&lt;/P&gt;&lt;P&gt;ranspt = ranuni(1239);&lt;/P&gt;&lt;P&gt;if ranspt &amp;lt; 0.6 then popul = 'SegA';else popu = 'SegB';&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the catch here is sometimes Rank = 'N' count can be higher in segB population. So I have to take the lowest Rank record count and adjust the other rank volume accordingly to get a even 50/50 count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to do it in multiple steps by counting no of records in Rank = N population and using _n_ to delete the Y records from segB but it wasn't working. I am sure there is a best way to do this and you experts can get this all done in a single data step!.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp; for your help!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 23:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-distribution-of-records/m-p/96942#M20441</guid>
      <dc:creator>vicky07</dc:creator>
      <dc:date>2013-06-05T23:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Random distribution of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Random-distribution-of-records/m-p/96943#M20442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Compute the required sampling rates in each strata (Y and N), use surveyselect to draw the sample and use a WHERE clause to drop the strata=N from the selected sample:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;STRONG&gt;data vendor_seg;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Input ID $ 1-4 Rank $ 6;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1771 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3456 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5134 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;9087 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2829 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2749 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;9987 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3094 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2938 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;8320 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5681 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2922 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;0987 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1108 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3879 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;8734 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1930 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;4752 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5609 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;7541 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;8745 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;9109 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5904 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;7145 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;0876 N&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2939 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;7340 Y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=vendor_seg; by rank; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;create table strataRate as&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rank, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.2*sum(n)/n as _rate_&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select rank, count(*) as n from vendor_seg group by rank);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc surveyselect data=vendor_seg seed=1239&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rate=strataRate out=sample(where=(rank="Y"));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;strata rank;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 03:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Random-distribution-of-records/m-p/96943#M20442</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-06-06T03:01:28Z</dc:date>
    </item>
  </channel>
</rss>

