<?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: Replace missing variables (na) by random numbers within range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462464#M117746</link>
    <description>Hi Risk, yes, it can be numeric. Thanks!</description>
    <pubDate>Tue, 15 May 2018 18:41:07 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2018-05-15T18:41:07Z</dc:date>
    <item>
      <title>Replace missing variables (na) by random numbers within range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462456#M117739</link>
      <description>&lt;P&gt;How to replace missing variables (na) by random numbers between 1 through 10? numbers can be repeated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input a $;
cards;
1
2
na
na
4
na
na
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks millions in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 18:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462456#M117739</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-05-15T18:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing variables (na) by random numbers within range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462463#M117745</link>
      <description>&lt;P&gt;Shouldn't 'a' be a numeric variable?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, see the article &lt;A href="https://blogs.sas.com/content/iml/2015/10/05/random-integers-sas.html" target="_self"&gt;"How to generate&amp;nbsp;random integers in SAS".&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;If you are reading a numeric variable x, then the modern code is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if missing(x) then x = rand("Integer", 1, 10);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here I am assuming that you want a random integer. If you are using an old version of SAS, see the article for an alternative syntax.&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 18:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462463#M117745</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-05-15T18:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing variables (na) by random numbers within range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462464#M117746</link>
      <description>Hi Risk, yes, it can be numeric. Thanks!</description>
      <pubDate>Tue, 15 May 2018 18:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462464#M117746</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-05-15T18:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing variables (na) by random numbers within range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462478#M117750</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you see anything wrong here? Month_of_birth is now a numeric variable with missing .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want; set have;&lt;BR /&gt;if missing(Month_of_birth) then Month_of_birth=rand("Integer", 1, 31);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: The first argument of the RAND function must be a character string with a value of&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BERNOULLI, BETA, BINOMIAL, CAUCHY, CHISQUARE, ERLANG, EXPONENTIAL, F, GAMMA, GAUSSIAN,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GEOMETRIC, HYPERGEOMETRIC, LOGNORMAL, NEGB, NORMAL, POISSON, T, TABLE, TRIANGULAR, UNIFORM,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or WEIBULL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 19:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462478#M117750</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-05-15T19:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing variables (na) by random numbers within range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462486#M117753</link>
      <description>&lt;P&gt;As I indicated in my answer (and say explicitly in the article that I asked you to read), the "Integer" distribution was introduced in the past few releases of SAS. The error says that you are not using a recent version of SAS. See the article for how to define the&amp;nbsp;%RandBetween macro and use %RandBetween(1,31).&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 19:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462486#M117753</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-05-15T19:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing variables (na) by random numbers within range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462494#M117760</link>
      <description>&lt;P&gt;Updating what worked:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro RandBetween(min, max);
   (&amp;amp;min + floor((1+&amp;amp;max-&amp;amp;min)*rand("uniform")))
%mend;

data success; set have; 
if Month_of_birth=. then Month_of_birth = %RandBetween(1, 12);
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 19:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-variables-na-by-random-numbers-within-range/m-p/462494#M117760</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-05-15T19:43:18Z</dc:date>
    </item>
  </channel>
</rss>

