<?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: What does CALL STREAMINIT do and how does it work with rand function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900776#M355991</link>
    <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt; for this advice. Do you mind to share you thoughts on why it might imply the original author does not understand CALL STREAMINIT by the manner it was written?</description>
    <pubDate>Mon, 30 Oct 2023 18:57:37 GMT</pubDate>
    <dc:creator>LL5</dc:creator>
    <dc:date>2023-10-30T18:57:37Z</dc:date>
    <item>
      <title>What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900765#M355984</link>
      <description>&lt;P&gt;I found some basic explanation on call streaminit routine &lt;SPAN&gt;to specify a seed value to use for subsequent random number generation by the RAND function. However, I try to understand better of this concept and ideally with a specific use case.&amp;nbsp; I see the following code which is to create a new variable "rand_num" based on the customer invoice number variable named "invoice_nm". &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I wonder if anyone could guide me or explain the meaning of the codes for data step that created the dataset "final"? I do not have any additional information on the big pictures of this program, all I know is that is for filling the missing data or for data imputation purpose. Any advice&amp;nbsp;would be greatly appreciated.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data simple_data;
    input invoice_nm;
    datalines;
13011725
48125891
58509176
82478132
44424919
10605934
31859010
12825087
37489700
18547980
29057182
36961654
38808747
41324767
87265097
79995217
76234154
58838431
85097443
34942259
96916424
;
run;

data final;
	set simple_data;
	call streaminit(invoice_nm);
	rand_num = round(rand('uniform'),0.001) ;
run;

&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2023 18:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900765#M355984</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2023-10-30T18:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900767#M355985</link>
      <description>Have you seen the blogs on ramdom numbers? Ex.: &lt;A href="https://blogs.sas.com/content/iml/2011/08/31/random-number-streams-in-sas-how-do-they-work.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2011/08/31/random-number-streams-in-sas-how-do-they-work.html&lt;/A&gt; or the papers: &lt;A href="https://www.lexjansen.com/search/searchresults.php?q=streaminit" target="_blank"&gt;https://www.lexjansen.com/search/searchresults.php?q=streaminit&lt;/A&gt;</description>
      <pubDate>Mon, 30 Oct 2023 18:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900767#M355985</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2023-10-30T18:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900768#M355986</link>
      <description>&lt;P&gt;From the documentation of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0gw58qo85qp56n1kbpiz50ww8lv.htm" target="_blank" rel="noopener"&gt;CALL STREAMINIT Routine&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;All the streams in the DATA step are initialized by using the seed value in the first call to STREAMINIT. Subsequent calls to STREAMINIT are ignored.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;So only the first number of the dataset is used.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 18:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900768#M355986</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-10-30T18:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900773#M355988</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; for sharing the documentation link (the one I viewed previously has less information) and specifically highlighting the summary of what it does.</description>
      <pubDate>Mon, 30 Oct 2023 18:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900773#M355988</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2023-10-30T18:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900774#M355989</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3492"&gt;@JosvanderVelden&lt;/a&gt; for sharing these links and resources.</description>
      <pubDate>Mon, 30 Oct 2023 18:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900774#M355989</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2023-10-30T18:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900775#M355990</link>
      <description>&lt;P&gt;It sounds like you inherited this code.&amp;nbsp; It's scary to inherit code like this, where it probably works, but the manner in which it is written suggests that the author does not understand CALL STREAMINIT.&amp;nbsp; It suggests you should take extra caution when reviewing other code from the same source.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 18:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900775#M355990</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-30T18:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900776#M355991</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt; for this advice. Do you mind to share you thoughts on why it might imply the original author does not understand CALL STREAMINIT by the manner it was written?</description>
      <pubDate>Mon, 30 Oct 2023 18:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900776#M355991</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2023-10-30T18:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900799#M355995</link>
      <description>&lt;P&gt;As Kurt mentioned, CALL STREAMINIT() is an unusual routine, where only the first call to STREAMINIT() in a step has an effect, subsequent calls are ignored.&amp;nbsp; When I see this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
	set simple_data;
	call streaminit(invoice_nm);
	rand_num = round(rand('uniform'),0.001) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It makes me think that the author might have thought there was value in calling STREAMINIT once for each record in SIMPLE_DATA, and that there was value in using a different seed value (the value of INVOICE_NM) on each call.&amp;nbsp; In fact the code is equivalent to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
	set simple_data;
	if _n_=1 then call streaminit(invoice_nm) ;
	rand_num = round(rand('uniform'),0.001) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To me, the second code makes clear that the author knows that STREAMINIT is only executed once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For argument's sake, some might say that my second code is less efficient, because on every iteration of the DATA step, it needs to test IF _N_=1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So while I can't say that the original code is wrong, if I saw it, it would raise a warning flag for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But others may disagree.&amp;nbsp; The docs have examples like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Class;
   set Sashelp.Class(where=(sex='M'));
   call streaminit( 'mt64', 27182818284590 );
   Random = rand( 'uniform' );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which I don't love for the same reason.&amp;nbsp; But at least the examples all pass literal values to STREAMINIT, and not variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 20:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900799#M355995</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-30T20:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: What does CALL STREAMINIT do and how does it work with rand function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900803#M355998</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt; for explaining this thoroughly, it really helps a lot. Now I assume this code is probably meant to calling STREAMINIT based on the first value of the invoice_nm to avoid changing value for the entire rand_num columns in the case of re-run. Either way, your advice is very insightful and thoughtful. I am accepting this as a solution.</description>
      <pubDate>Mon, 30 Oct 2023 20:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-CALL-STREAMINIT-do-and-how-does-it-work-with-rand/m-p/900803#M355998</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2023-10-30T20:49:43Z</dc:date>
    </item>
  </channel>
</rss>

