<?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: Macro for dynamically assigning new values based on random numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/427167#M105321</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13683"&gt;@ArtC&lt;/a&gt;&amp;nbsp;Cool !&amp;nbsp; Maybe I get confused by OP. Hope one day we could have a meet in the future.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2018 12:41:46 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-01-12T12:41:46Z</dc:date>
    <item>
      <title>Macro for dynamically assigning new values based on random numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/426646#M105132</link>
      <description>&lt;P&gt;Hello - I am relatively new to SAS and a first time poster. I have some code that assigns a random integer to a set of IDs. I have posted this below. Is it possible to create a new ID variable chosen by the user based on these random variables? Ive had trouble with this because the number of new IDs I want to assign inherently changes. Is there a better way to go about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data_1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Input id_no;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 123&lt;/P&gt;&lt;P&gt;&amp;nbsp; 456&lt;/P&gt;&lt;P&gt;&amp;nbsp; 789&lt;/P&gt;&lt;P&gt;&amp;nbsp; 987&lt;/P&gt;&lt;P&gt;&amp;nbsp; 654&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro assign_rand(no_rand=);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %macro randbetween(min,max);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; (&amp;amp;Min + floor((1+&amp;amp;max-&amp;amp;min)*Rand("uniform)));&lt;/P&gt;&lt;P&gt;&amp;nbsp; %mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data data_1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; set data_1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; random_no = %randbetween(1,&amp;amp;no_rand);&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 20:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/426646#M105132</guid>
      <dc:creator>mike_579357</dc:creator>
      <dc:date>2018-01-10T20:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamically assigning new values based on random numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/426657#M105136</link>
      <description>&lt;P&gt;Are you looking for something along these lines?&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/fd94b0b6e78815430c1340e8c19f8644" target="_blank"&gt;https://gist.github.com/statgeek/fd94b0b6e78815430c1340e8c19f8644&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185958"&gt;@mike_579357&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello - I am relatively new to SAS and a first time poster. I have some code that assigns a random integer to a set of IDs. I have posted this below. Is it possible to create a new ID variable chosen by the user based on these random variables? Ive had trouble with this because the number of new IDs I want to assign inherently changes. Is there a better way to go about this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data data_1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Input id_no;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 123&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 456&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 789&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 987&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 654&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro assign_rand(no_rand=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %macro randbetween(min,max);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; (&amp;amp;Min + floor((1+&amp;amp;max-&amp;amp;min)*Rand("uniform)));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; data data_1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; set data_1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; random_no = %randbetween(1,&amp;amp;no_rand);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 21:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/426657#M105136</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-10T21:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamically assigning new values based on random numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/426865#M105213</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data data_1;
  Input id_no;
  cards;
  123
  456
  789
  987
  654
;
run;


  data _null_;
    set data_1 end=last;
 if _n_=1 then call execute('data want;');
 call execute(catt('random_no=1 + floor(',id_no,'*Rand("uniform"));output;'));
 if last then call execute('run;');
  run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jan 2018 13:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/426865#M105213</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-11T13:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamically assigning new values based on random numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/426960#M105249</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; cool code, but would the following be a simpler approach?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  data want2;
   set data_1;
   random_no=1+floor(id_no*rand('uniform'));
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do we need to be sure that the random identifiers are unique?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 19:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/426960#M105249</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2018-01-11T19:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamically assigning new values based on random numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/427167#M105321</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13683"&gt;@ArtC&lt;/a&gt;&amp;nbsp;Cool !&amp;nbsp; Maybe I get confused by OP. Hope one day we could have a meet in the future.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 12:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamically-assigning-new-values-based-on-random/m-p/427167#M105321</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-12T12:41:46Z</dc:date>
    </item>
  </channel>
</rss>

