<?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: Missing values produced in simulation in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Missing-values-produced-in-simulation/m-p/752807#M29813</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/336370"&gt;@tumul&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue with your DATA step is that you replaced the constant initial value for variable &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; in the RETAIN statement with the variable name &lt;FONT face="courier new,courier"&gt;col_C&lt;/FONT&gt;. This changes the meaning of the statement. Now, variables &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;col_C&lt;/FONT&gt; are retained (which is redundant for the latter because &lt;FONT face="courier new,courier"&gt;col_C&lt;/FONT&gt; is read by the SET statement and therefore automatically retained) and &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; does &lt;EM&gt;not&lt;/EM&gt; receive an initial value, hence it's missing and all calculations involving &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; are bound to fail with the notorious&amp;nbsp;&lt;SPAN&gt;"Missing values were generated&amp;nbsp;..." note.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To avoid this problem, consider this variant of your DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data samples(drop = k n);
call streaminit(27182818);
i = _n_;
set simulation_data nobs = m;
n = m;
k = col_C;
do p=1 to n;
  set simulation_data point = p;
  if rand ("uniform") &amp;lt; k/n then do;
    output;
    k = k-1;
  end;
  n = n-1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It creates the random samples, identified by variable &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt;=1, 2, ...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A slight modification of the above DATA step creates the sums &lt;FONT face="courier new,courier"&gt;s&lt;/FONT&gt; of &lt;FONT face="courier new,courier"&gt;col_B&lt;/FONT&gt; values by &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt; directly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sums(keep = i s);
call streaminit(27182818);
i = _n_;
set simulation_data(keep = col_C) nobs = m;
n = m;
k = col_C;
do p=1 to n;
  set simulation_data(keep = col_B) point = p;
  if rand ("uniform") &amp;lt; k/n then do;
    s = sum(s, col_B);
    k = k-1;
  end;
  n = n-1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(The KEEP= dataset options are just to improve performance.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jul 2021 08:55:02 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-07-08T08:55:02Z</dc:date>
    <item>
      <title>Missing values produced in simulation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Missing-values-produced-in-simulation/m-p/752780#M29811</link>
      <description>&lt;P&gt;Hello guys ! I am new to SAS, please help me figure this out.&lt;/P&gt;&lt;P&gt;I have a dataset that looks like this (name : simulation_data) :-&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;col_A&amp;nbsp; &amp;nbsp;col_B&amp;nbsp; &amp;nbsp;col_C&lt;BR /&gt;101&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;BR /&gt;102&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22&lt;BR /&gt;103&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;BR /&gt;104&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;BR /&gt;105&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;100 data points&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now, On this data I have to do a simulation kind of thing where for each entry in 'col_c' (lets say first entry : 20) I have to select 20 random numbers from col_B and take the sum of those 20 selected enties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for all the 100 observations in 'col_C', col_C amount of entries have to be selected from 'col_B', sum of all those selected entries have to be taken and the number obtained in each interation has to be appended in a seperate dataset (or in this dataset itself).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the first step of the process (i.e. to take col_C number of elements from the simulation_data at random) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data col_c_data;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; set simulation_data nobs = n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; retain k col_C;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if rand ("uniform") &amp;lt; k/n then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; k = k-1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; n = n-1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a standard code to take "k" random entries from a variable with "n" observation&lt;BR /&gt;(code obtained from : &lt;A href="https://sasnrd.com/sas-random-sampling-without-replacement/" target="_blank"&gt;https://sasnrd.com/sas-random-sampling-without-replacement/&lt;/A&gt;)&lt;BR /&gt;but col_c_data produced is an empty one and LOG says that "Missing values were generated as a result of performing an operation on missing values".&lt;/P&gt;&lt;P&gt;apart from the method I am familiar with "proc survey select"&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 07:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Missing-values-produced-in-simulation/m-p/752780#M29811</guid>
      <dc:creator>tumul</dc:creator>
      <dc:date>2021-07-08T07:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: Missing values produced in simulation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Missing-values-produced-in-simulation/m-p/752807#M29813</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/336370"&gt;@tumul&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue with your DATA step is that you replaced the constant initial value for variable &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; in the RETAIN statement with the variable name &lt;FONT face="courier new,courier"&gt;col_C&lt;/FONT&gt;. This changes the meaning of the statement. Now, variables &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;col_C&lt;/FONT&gt; are retained (which is redundant for the latter because &lt;FONT face="courier new,courier"&gt;col_C&lt;/FONT&gt; is read by the SET statement and therefore automatically retained) and &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; does &lt;EM&gt;not&lt;/EM&gt; receive an initial value, hence it's missing and all calculations involving &lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; are bound to fail with the notorious&amp;nbsp;&lt;SPAN&gt;"Missing values were generated&amp;nbsp;..." note.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To avoid this problem, consider this variant of your DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data samples(drop = k n);
call streaminit(27182818);
i = _n_;
set simulation_data nobs = m;
n = m;
k = col_C;
do p=1 to n;
  set simulation_data point = p;
  if rand ("uniform") &amp;lt; k/n then do;
    output;
    k = k-1;
  end;
  n = n-1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It creates the random samples, identified by variable &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt;=1, 2, ...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A slight modification of the above DATA step creates the sums &lt;FONT face="courier new,courier"&gt;s&lt;/FONT&gt; of &lt;FONT face="courier new,courier"&gt;col_B&lt;/FONT&gt; values by &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt; directly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sums(keep = i s);
call streaminit(27182818);
i = _n_;
set simulation_data(keep = col_C) nobs = m;
n = m;
k = col_C;
do p=1 to n;
  set simulation_data(keep = col_B) point = p;
  if rand ("uniform") &amp;lt; k/n then do;
    s = sum(s, col_B);
    k = k-1;
  end;
  n = n-1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(The KEEP= dataset options are just to improve performance.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 08:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Missing-values-produced-in-simulation/m-p/752807#M29813</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-08T08:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Missing values produced in simulation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Missing-values-produced-in-simulation/m-p/752813#M29815</link>
      <description>&lt;P&gt;It works ! now i understood my mistake...thank you for helping me out&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 09:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Missing-values-produced-in-simulation/m-p/752813#M29815</guid>
      <dc:creator>tumul</dc:creator>
      <dc:date>2021-07-08T09:15:06Z</dc:date>
    </item>
  </channel>
</rss>

