<?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: Assign Random Values for Each Variables and Get the Maximum Value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406010#M98808</link>
    <description>&lt;P&gt;Here is my desired output,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Desired.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16106i48365C7E3DF412FC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Desired.png" alt="Desired.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 15:54:35 GMT</pubDate>
    <dc:creator>ertr</dc:creator>
    <dc:date>2017-10-20T15:54:35Z</dc:date>
    <item>
      <title>Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405634#M98706</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sample data set as below, I want to assign Random values between zero and one for each variables but it should in a new variables. exceptionally, if the limit variables includes missing values then it will assign zero instead of Random values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample Data Set&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length CUST_ID 8 DEFAULT_DATE 8 Limit_1 8 Limit_2 8 Limit_3 8;
Infile Datalines Missover;
Input CUST_ID DEFAULT_DATE  Limit_1 Limit_2 Limit_3;
Format  DEFAULT_DATE date9.;
Datalines;
0001 21000 10000 10500 11000 
0002 21031 . . .
0003 21062 20000 20500 21000 
0004 21092 . . . 
0005 21123 30000 30500 31000
0006 21153 . . .
0007 21184 40000 40500 41000 
0008 21215 . . .
0009 21243 50000 50500 51000 
00010 21274 . . . 
00011 21304 60000 60500 10000
00012 21335 . . .
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Random Data Should like this;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Random.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16013i36F0D5A4CB76F850/image-size/large?v=v2&amp;amp;px=999" role="button" title="Random.png" alt="Random.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My real purpose is the get Limit value which is equal to Maximum Random Value. I tried to explain in the following data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Desired.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16015iAC6492F4E6D152AA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Desired.png" alt="Desired.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this process can make by SAS codes but I'm not sure how to do, on the other hand, maybe there can be more pratic ways&amp;nbsp; to do this method without using SAS code. I'd be glad, if you help me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 16:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405634#M98706</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2017-10-19T16:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405655#M98718</link>
      <description>&lt;P&gt;Here's what I think you want. Not sure what you're actually after here...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array limits(*) limit_1 - limit_3;
	array _rand(*) limit_Rand1-limit_rand3;

	do i=1 to dim(limits);
		if not missing(limits(i)) then
			_rand(i) = rand('uniform');
		else _rand(i) = 0;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Oct 2017 16:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405655#M98718</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-19T16:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405891#M98767</link>
      <description>&lt;P&gt;Yes but I want to get the maximum value, I mean;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if limit_Rand_03 greater than&amp;nbsp;&lt;SPAN&gt;limit_Rand_01 and&amp;nbsp;limit_Rand_02 then, it should bring Limit_1's original value in a new column(MaxValue).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if limit_Rand_02 greater than&amp;nbsp;limit_Rand_01 and&amp;nbsp;limit_Rand_03 then, it should bring Limit_2s original value in a new column(MaxValue).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if limit_Rand_03 greater than&amp;nbsp;limit_Rand_02 and&amp;nbsp;limit_Rand_03 then, it should bring Limit_3s original value in a new column(MaxValue).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I do this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 08:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405891#M98767</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2017-10-20T08:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405896#M98771</link>
      <description>&lt;P&gt;Actually, this will give the Maximum Value; (By the way, is there a way to write this more easy-&amp;gt;MAX(Limit_Rand1,Limit_Rand2,Limit_Rand3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL; 
Create Table Want2 As
SELECT *, MAX(limit_Rand1,limit_rand2,limit_rand3) As MaxVal From Want;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I want to pull the limit value , which is eqaul to number of Rand variable, I mean,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if limit_Rand_03 greater than&amp;nbsp;&lt;SPAN&gt;limit_Rand_01 and&amp;nbsp;limit_Rand_02 then, it should bring Limit_1's original value in a new column(MaxValue).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if limit_Rand_02 greater than&amp;nbsp;limit_Rand_01 and&amp;nbsp;limit_Rand_03 then, it should bring Limit_2s original value in a new column(MaxValue).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if limit_Rand_03 greater than&amp;nbsp;limit_Rand_02 and&amp;nbsp;limit_Rand_03 then, it should bring Limit_3s original value in a new column(MaxValue).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 09:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405896#M98771</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2017-10-20T09:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405976#M98795</link>
      <description>&lt;P&gt;Post the expected output for your data. It sounds like you just want a random value from the 3 values? Is that what you're trying to do here? If so, I would use RANDTABLE instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use MAX() to find the maximum values.&lt;/P&gt;
&lt;P&gt;You can use WHICHN to find the index of that value.&lt;/P&gt;
&lt;P&gt;Then you can use that index to find the value in the original array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can use RANDTABLE or RAND to generate a random number between 1 and 3 and just use that instead.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 14:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/405976#M98795</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T14:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406010#M98808</link>
      <description>&lt;P&gt;Here is my desired output,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Desired.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16106i48365C7E3DF412FC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Desired.png" alt="Desired.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 15:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406010#M98808</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2017-10-20T15:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406011#M98809</link>
      <description>&lt;P&gt;Post it as text, that's not legible.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 15:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406011#M98809</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T15:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406014#M98810</link>
      <description>&lt;P&gt;actually, it doesn't matter, the answer is the same:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use MAX() to find the maximum values.&lt;/P&gt;
&lt;P&gt;You can use WHICHN to find the index of that value.&lt;/P&gt;
&lt;P&gt;Then you can use that index to find the value in the original array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is much easier in a data step. If you need further help, post your code and log and current output.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 15:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406014#M98810</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T15:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406032#M98811</link>
      <description>&lt;P&gt;It seems okay, does it also seem okay for you?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array limits(*) limit_1 - limit_3;
	array _rand(*) limit_Rand1-limit_rand3;

	do i=1 to dim(limits);
		if not missing(limits(i)) then
			_rand(i) = rand('uniform');
		else _rand(i) = 0;
	end;
			MaxVal=Max(of _rand(*));
			IndexValue=WhichN(MaxVal,of _rand(*));
			DesiredValue=limits(IndexValue);

	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 16:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406032#M98811</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2017-10-20T16:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Random Values for Each Variables and Get the Maximum Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406033#M98812</link>
      <description>&lt;P&gt;I still think it's overkill. If you're trying to randomly select a value - and maximum isn't really true, it's just a random value from the 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array limits(*) limit_1 - limit_3;
        index = rantbl(25, 1/3, 1/3, 1/3);
        desired_value = limits(index);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Oct 2017 16:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Random-Values-for-Each-Variables-and-Get-the-Maximum/m-p/406033#M98812</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T16:59:14Z</dc:date>
    </item>
  </channel>
</rss>

