<?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 changing a percentage (or set #) of a vars observations... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/changing-a-percentage-or-set-of-a-vars-observations/m-p/20177#M3121</link>
    <description>What is the simplest way to change a percentage of a vars observations in a data set based on a condition on that single var? &lt;BR /&gt;
&lt;BR /&gt;
For example:  I want to change 50% of the observations in a data set where var A = 1 to var A = 2?  (50 current obs where A =1 are to be changed to 25 obs where A = 1 and 25 where A = 2.)&lt;BR /&gt;
&lt;BR /&gt;
Even the ability to change x-number of obs where var A = 1 to A = 2 would work. &lt;BR /&gt;
&lt;BR /&gt;
For example:  100 obs where A = 1; A is changed to 2  &lt;BR /&gt;
&lt;BR /&gt;
Normally I have the luxury of a second variable to condition against but in this case I don't have anything to use.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
    <pubDate>Wed, 12 May 2010 07:01:54 GMT</pubDate>
    <dc:creator>veblen</dc:creator>
    <dc:date>2010-05-12T07:01:54Z</dc:date>
    <item>
      <title>changing a percentage (or set #) of a vars observations...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/changing-a-percentage-or-set-of-a-vars-observations/m-p/20177#M3121</link>
      <description>What is the simplest way to change a percentage of a vars observations in a data set based on a condition on that single var? &lt;BR /&gt;
&lt;BR /&gt;
For example:  I want to change 50% of the observations in a data set where var A = 1 to var A = 2?  (50 current obs where A =1 are to be changed to 25 obs where A = 1 and 25 where A = 2.)&lt;BR /&gt;
&lt;BR /&gt;
Even the ability to change x-number of obs where var A = 1 to A = 2 would work. &lt;BR /&gt;
&lt;BR /&gt;
For example:  100 obs where A = 1; A is changed to 2  &lt;BR /&gt;
&lt;BR /&gt;
Normally I have the luxury of a second variable to condition against but in this case I don't have anything to use.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Wed, 12 May 2010 07:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/changing-a-percentage-or-set-of-a-vars-observations/m-p/20177#M3121</guid>
      <dc:creator>veblen</dc:creator>
      <dc:date>2010-05-12T07:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: changing a percentage (or set #) of a vars observations...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/changing-a-percentage-or-set-of-a-vars-observations/m-p/20178#M3122</link>
      <description>If it doesn't have to be exatly 50/50 then you could use ranuni() in the way:&lt;BR /&gt;
&lt;BR /&gt;
if a=1 then&lt;BR /&gt;
do;&lt;BR /&gt;
  if ranuni()&amp;gt;0.5 then a=2;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
If it has to be exactly 50/50 but doesn't have to be random then you just could count the total number of obs where A=1 in a first pass through the data and then in a second pass set half of these obs where A=1 to A=2.&lt;BR /&gt;
&lt;BR /&gt;
If it has to be exactly 50/50 but random which record is set to A=2 then it's getting a bit harder. &lt;BR /&gt;
You would still have to count the total number of obs where A=1 in a first pass through the data but then use a more sophisticated way for assigning 50% of obs where A=1 with A=2.&lt;BR /&gt;
The approach I have in mind is mainly the same like picking a random sample (only that instead of writing the data to an sample data set you would assign the value 2 to A). This is the link to the code of how to pick the values together with some explanations: &lt;A href="http://groups.google.com/group/comp.soft-sys.sas/browse_thread/thread/231bef19aaf0f2b1/fdabf8498967b267?lnk=gst&amp;amp;q=patrick+random#fdabf8498967b267" target="_blank"&gt;http://groups.google.com/group/comp.soft-sys.sas/browse_thread/thread/231bef19aaf0f2b1/fdabf8498967b267?lnk=gst&amp;amp;q=patrick+random#fdabf8498967b267&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Wed, 12 May 2010 13:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/changing-a-percentage-or-set-of-a-vars-observations/m-p/20178#M3122</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-05-12T13:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: changing a percentage (or set #) of a vars observations...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/changing-a-percentage-or-set-of-a-vars-observations/m-p/20179#M3123</link>
      <description>THANK YOU Patrick!&lt;BR /&gt;
&lt;BR /&gt;
It worked like a charm.</description>
      <pubDate>Thu, 13 May 2010 16:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/changing-a-percentage-or-set-of-a-vars-observations/m-p/20179#M3123</guid>
      <dc:creator>veblen</dc:creator>
      <dc:date>2010-05-13T16:06:35Z</dc:date>
    </item>
  </channel>
</rss>

