<?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 Randomly assign values (3,4,5) to a combined variable (includes 3-5) based on percentages in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973965#M377769</link>
    <description>&lt;P&gt;Hello. I have a variable in my main dataset that looks like this:&lt;/P&gt;
&lt;PRE&gt;Number of previous live births (PLBs)&lt;BR /&gt;0 PLBs = 0
1 PLBs = 1
2 PLBs = 2
3 PLBs = 3-5
4 PLBs = 6+&lt;/PRE&gt;
&lt;P&gt;I used another dataset that has a fully continuous PLB variable to figure out the percentage of observations that have 3, 4, and 5 PLBs. Now, I would like to use those percentages to randomly pull 60%, 25%, and 15% to be reassigned as 3, 4, and 5 PLBs (respectively) so that I have a continuous variable in my main dataset. I've been playing around with proc surveyselect but I can't figure out how to make this work. Let me know if I can clarify anything. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: there seems to be some confusion (although I can't understand why anyone familiar with data would be confused. but I digress). My data looks something like this, and the 'want' variable is what I want, where 60% of the '3' category is assigned as 3, 25% assigned as 4, and 15% assigned as 5. Thanks!&lt;/P&gt;
&lt;PRE&gt;ID    PLB    WANT&lt;BR /&gt;1      3       4&lt;BR /&gt;2      1       1&lt;BR /&gt;3      2       2&lt;BR /&gt;4      3       3&lt;BR /&gt;5      4       4&lt;BR /&gt;6      3       5&lt;/PRE&gt;</description>
    <pubDate>Tue, 02 Sep 2025 20:41:55 GMT</pubDate>
    <dc:creator>joachimg</dc:creator>
    <dc:date>2025-09-02T20:41:55Z</dc:date>
    <item>
      <title>Randomly assign values (3,4,5) to a combined variable (includes 3-5) based on percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973965#M377769</link>
      <description>&lt;P&gt;Hello. I have a variable in my main dataset that looks like this:&lt;/P&gt;
&lt;PRE&gt;Number of previous live births (PLBs)&lt;BR /&gt;0 PLBs = 0
1 PLBs = 1
2 PLBs = 2
3 PLBs = 3-5
4 PLBs = 6+&lt;/PRE&gt;
&lt;P&gt;I used another dataset that has a fully continuous PLB variable to figure out the percentage of observations that have 3, 4, and 5 PLBs. Now, I would like to use those percentages to randomly pull 60%, 25%, and 15% to be reassigned as 3, 4, and 5 PLBs (respectively) so that I have a continuous variable in my main dataset. I've been playing around with proc surveyselect but I can't figure out how to make this work. Let me know if I can clarify anything. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: there seems to be some confusion (although I can't understand why anyone familiar with data would be confused. but I digress). My data looks something like this, and the 'want' variable is what I want, where 60% of the '3' category is assigned as 3, 25% assigned as 4, and 15% assigned as 5. Thanks!&lt;/P&gt;
&lt;PRE&gt;ID    PLB    WANT&lt;BR /&gt;1      3       4&lt;BR /&gt;2      1       1&lt;BR /&gt;3      2       2&lt;BR /&gt;4      3       3&lt;BR /&gt;5      4       4&lt;BR /&gt;6      3       5&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Sep 2025 20:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973965#M377769</guid>
      <dc:creator>joachimg</dc:creator>
      <dc:date>2025-09-02T20:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly assign values (3,4,5) to a combined variable (includes 3-5) based on percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973967#M377771</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393705"&gt;@joachimg&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello. I have a variable in my main dataset that looks like this:&lt;/P&gt;
&lt;PRE&gt;Number of previous live births&lt;BR /&gt;0 = 0
1 = 1
2 = 2
3 = 3-5
4 = 6+&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Data sets don't look like this. If we are going to write sample code for you, we need to see (a portion of) the actual data set (or the actual data set with fake numbers). Please help us help you by providing the data set as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;), this is the only acceptable way to show us a data set; do not provide the data as Excel files or text files, do not provide the data as copy/paste from Excel, &lt;EM&gt;etc&lt;/EM&gt;. By the way, we have asked you to provide data in the proper form &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;previously&lt;/A&gt;, please don't make us repeatedly request that you use the proper form.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2025 20:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973967#M377771</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-09-02T20:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly assign values (3,4,5) to a combined variable (includes 3-5) based on percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973968#M377772</link>
      <description>&lt;P&gt;Hello, I specified in my original post that this is a VARIABLE in a dataset, not a dataset. This is how you would see the variable described in a data dictionary or codebook.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2025 20:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973968#M377772</guid>
      <dc:creator>joachimg</dc:creator>
      <dc:date>2025-09-02T20:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly assign values (3,4,5) to a combined variable (includes 3-5) based on percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973969#M377773</link>
      <description>&lt;P&gt;SAS doesn't work on data dictionaries or codebooks, it works on variables in data sets. As such, we need to see (a portion of) your data set in a usable form, which is defined at the link I gave.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2025 20:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973969#M377773</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-09-02T20:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly assign values (3,4,5) to a combined variable (includes 3-5) based on percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973970#M377774</link>
      <description>&lt;P&gt;Suppose I assumed the people on here were familiar enough with how data works that my original post would be clear. I've updated the post now.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2025 20:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/973970#M377774</guid>
      <dc:creator>joachimg</dc:creator>
      <dc:date>2025-09-02T20:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly assign values (3,4,5) to a combined variable (includes 3-5) based on percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/974007#M377779</link>
      <description>&lt;P&gt;Does you just want to assign&amp;nbsp;&lt;SPAN&gt;60% of the '3'&amp;nbsp; to be 3, 25% of the '3'&amp;nbsp; to be 4, 15% of the '3'&amp;nbsp; to be 5 ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If it was, that would be very easy to implement by RAND() function with TABLE distribution.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
call streaminit(123);
do id=1 to 1000;
 plb=rand('table',0.25,0.25,0.4);
 output;
end;
stop;
run;

data want;
 set have;
 call streaminit(123);
 if plb=3 then want=2+rand('table',0.6,0.25);
 else want=plb;
run;


/*Check the result*/
proc freq data=want(where=(plb=3));
table want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1756885455970.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109572i0FB5C14C71927F19/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1756885455970.png" alt="Ksharp_0-1756885455970.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Sep 2025 07:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/974007#M377779</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-09-03T07:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly assign values (3,4,5) to a combined variable (includes 3-5) based on percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/974034#M377788</link>
      <description>This is perfect, thank you so much for your help!!</description>
      <pubDate>Wed, 03 Sep 2025 14:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomly-assign-values-3-4-5-to-a-combined-variable-includes-3-5/m-p/974034#M377788</guid>
      <dc:creator>joachimg</dc:creator>
      <dc:date>2025-09-03T14:14:56Z</dc:date>
    </item>
  </channel>
</rss>

