<?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 Creating code for combining rows and then randomly selecting and capping then have remainder in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/784044#M250123</link>
    <description>&lt;P&gt;How do I create code for A1 and A2 by combining rows (A5, A6, A7, A8) to get a random sample of 20000 capped records and then have the remaining records fall into (A5, A6, A7, A8) proportionally as seen in Screen Print? Column E shows the final Counts.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="creece37_0-1638583975891.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66395iD2301E5A70F646FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="creece37_0-1638583975891.png" alt="creece37_0-1638583975891.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 04 Dec 2021 02:13:16 GMT</pubDate>
    <dc:creator>creece37</dc:creator>
    <dc:date>2021-12-04T02:13:16Z</dc:date>
    <item>
      <title>Creating code for combining rows and then randomly selecting and capping then have remainder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/784044#M250123</link>
      <description>&lt;P&gt;How do I create code for A1 and A2 by combining rows (A5, A6, A7, A8) to get a random sample of 20000 capped records and then have the remaining records fall into (A5, A6, A7, A8) proportionally as seen in Screen Print? Column E shows the final Counts.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="creece37_0-1638583975891.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66395iD2301E5A70F646FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="creece37_0-1638583975891.png" alt="creece37_0-1638583975891.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 02:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/784044#M250123</guid>
      <dc:creator>creece37</dc:creator>
      <dc:date>2021-12-04T02:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating code for combining rows and then randomly selecting and capping then have remainder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/784070#M250133</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/408773"&gt;@creece37&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would use &lt;A href="https://documentation.sas.com/doc/en/statug/15.2/statug_surveyselect_overview.htm" target="_blank" rel="noopener"&gt;PROC SURVEYSELECT&lt;/A&gt; with the option &lt;A href="https://documentation.sas.com/doc/en/statug/15.2/statug_surveyselect_syntax07.htm#statug.surveyselect.selectallocnm" target="_blank" rel="noopener"&gt;ALLOC=PROP&lt;/A&gt; of the &lt;A href="https://documentation.sas.com/doc/en/statug/15.2/statug_surveyselect_syntax07.htm" target="_blank" rel="noopener"&gt;STRATA statement&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create example data for demonstration */

data have(drop=i);
do i=1 to 253957;
  MKT_ID=put(0A05x+(i&amp;gt;5442)+(i&amp;gt;31710)+(i&amp;gt;78977),hex3.);
  output;
end;
run;

/* Show distribution of MKT_ID values */

proc freq data=have;
tables MKT_ID;
run;

/* Draw random sample */

proc surveyselect data=have outall noprint
method=srs n=20000
seed=2718 out=samp;
strata MKT_ID / alloc=prop;
run;

/* Assign final MKT_IDs */

data want(drop=selected total--samplingweight);
set samp;
if selected then substr(MKT_ID,3)=ifc(MKT_ID in ('A05','A07'),'1','2');
run;

/* Check frequencies */

proc freq data=want;
tables MKT_ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Dec 2021 12:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/784070#M250133</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-12-04T12:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating code for combining rows and then randomly selecting and capping then have remainder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/784162#M250191</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do i=1 to 5442;
 id+1;mkt_id='A05';output;
end;
do i=1 to 26268;
 id+1;mkt_id='A06';output;
end;
do i=1 to 47267;
 id+1;mkt_id='A07';output;
end;
do i=1 to 174980;
 id+1;mkt_id='A08';output;
end;
run;






data temp;
 set have;
 if mkt_id in ('A05' 'A07') then group='A01';
  else group='A02';
run;
proc sort data=temp;by group;run;

/*a random sample of 20000*/
proc surveyselect data=temp out=want1 sampsize=(4151 15849) seed=123 outrandom noprint;
strata group;
run;
proc freq data=want1 ;
table group/list;
run;


/* remaining records */
proc sql;
create table want2 as
select * from temp where id not in (select id from want1);
quit;
proc freq data=want2;
table mkt_id/list;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Dec 2021 11:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/784162#M250191</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-12-05T11:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating code for combining rows and then randomly selecting and capping then have remainder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/785423#M250655</link>
      <description>This was helpful for capping te leads</description>
      <pubDate>Fri, 10 Dec 2021 16:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/785423#M250655</guid>
      <dc:creator>creece37</dc:creator>
      <dc:date>2021-12-10T16:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating code for combining rows and then randomly selecting and capping then have remainder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/785517#M250698</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;got better solution. His code could give you exact number as you showed in picture.&lt;/P&gt;
&lt;P&gt;But mine couldn't .&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-code-for-combining-rows-and-then-randomly-selecting-and/m-p/785517#M250698</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-12-11T09:52:27Z</dc:date>
    </item>
  </channel>
</rss>

