<?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: Getting Seed value used by SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809383#M319183</link>
    <description>&lt;P&gt;This is an interesting, but difficult task. I don't know how exactly SAS determines the seed from "the time of day" (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1fkiqt9ygapyxn1pd1w8manlpub.htm#p0t8oarf7a3y2cn15fakwbnvcbul" target="_blank" rel="noopener"&gt;RANUNI documentation&lt;/A&gt;), but I've just figured out how you can recover the actual seed from a&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ranuni(0)&lt;/FONT&gt; random number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS Log:&lt;/P&gt;
&lt;PRE&gt;1065  data _null_; t=time(); x=ranuni(0); nextseed=x*(2**31-1); put (t x nextseed)(=best16.); run;

t=71854.3729999065 x=&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;0.03466819368055&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt; nextseed=&lt;STRONG&gt;&lt;FONT size="4" color="#FF00FF"&gt;74449379&lt;/FONT&gt;&lt;/STRONG&gt;
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.06 seconds


1066  data _null_; t=time(); x=ranuni(0); nextseed=x*(2**31-1); put (t x nextseed)(=best16.); run;

t=71854.4820001125 x=&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;0.4605221792406&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt; nextseed=988963849
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


1067  data _null_; x=ranuni( &lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;195590984&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;); put x=best16.; run;

x=&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;0.03466819368055&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.06 seconds


1068  data _null_; x=ranuni(&lt;FONT size="4" color="#000000"&gt;&lt;STRONG&gt;1764153903&lt;/STRONG&gt;&lt;/FONT&gt;); put x=best16.; run;

x=&lt;STRONG&gt;&lt;FONT size="4" color="#008000"&gt;0.4605221792406
&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The mathematical formula for the seed appears to be:&amp;nbsp;&lt;FONT face="courier new,courier" size="4"&gt;seed = mod(58743242*nextseed, 2**31-1)&lt;/FONT&gt;. (The "magic" number&amp;nbsp;&lt;FONT face="courier new,courier" size="4"&gt;58743242&lt;/FONT&gt; is the multiplicative inverse of the "multiplier"&amp;nbsp;&lt;SPAN&gt;397204094 (mentioned in the RANUNI documentation) modulo &lt;FONT face="courier new,courier" size="4"&gt;2**31-1&lt;/FONT&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the first of the two examples above you can use this formula directly in a data step:&lt;/P&gt;
&lt;PRE&gt;1080  data _null_;
1081  nextseed=&lt;STRONG&gt;&lt;FONT size="4" color="#FF00FF"&gt;74449379&lt;/FONT&gt;&lt;/STRONG&gt;;
1082  seed = mod(58743242*nextseed, 2**31-1);
1083  put seed;
1084  run;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;195590984&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;For the second example you need more sophisticated code (or just use the Windows calculator calc.exe) to obtain the seed &lt;FONT face="courier new,courier" size="4" color="#000000"&gt;&lt;STRONG&gt;1764153903&lt;/STRONG&gt;&lt;/FONT&gt;, because&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;58743242*988963849 = 58094942711058458 &amp;gt; constant('exactint')&lt;/PRE&gt;
&lt;P&gt;on a Windows system so that the precision is insufficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the difficult question is how to obtain the seed value from the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt;&amp;nbsp;value (or is &lt;FONT face="courier new,courier"&gt;datetime()&lt;/FONT&gt;&amp;nbsp;used?), e.g.:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier" size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;195590984&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;71854.3729999065&lt;/FONT&gt; and&lt;/LI&gt;
&lt;LI&gt;&lt;FONT size="4" color="#000000"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;1764153903&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt; from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;71854.4820001125&lt;/FONT&gt;.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Obviously, you must not ignore &lt;EM&gt;fractions of a second&lt;/EM&gt;&amp;nbsp;when you "&lt;SPAN&gt;loop through the times" ...&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2022 18:54:21 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2022-04-22T18:54:21Z</dc:date>
    <item>
      <title>Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809295#M319130</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have a query, can someone help me?&lt;/P&gt;&lt;P&gt;While creating a Randomization schedule using SAS PROC PLAN if we are allowing SAS to utilize dynamic Seed value, is there any way we can get to know what is the Seed value used by SAS for creating the randomization schedule?&lt;/P&gt;&lt;P&gt;Part of SAS code:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt; _null_;&lt;/P&gt;&lt;P&gt;call symputx ('Seedval', tranwrd(put(ranuni(&lt;STRONG&gt;0&lt;/STRONG&gt;), best9.), '0.' , ' '));&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;plan&lt;/STRONG&gt; seed=&amp;amp;Seedval. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; factors BlockID= &lt;STRONG&gt;50&lt;/STRONG&gt; ordered Treatment=&lt;STRONG&gt;4&lt;/STRONG&gt; random /noprint&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=RandList BlockID nvals=(&lt;STRONG&gt;1&lt;/STRONG&gt; to &lt;STRONG&gt;50&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Treatment cvals=('Arm A' 'Arm A' 'Arm B' 'Arm B' );&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in my code I missed to output the macro value &amp;amp;Seedval.&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Sukumar&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 13:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809295#M319130</guid>
      <dc:creator>SukumarBalusamy</dc:creator>
      <dc:date>2022-04-22T13:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809298#M319132</link>
      <description>NO. you are not able to do it.&lt;BR /&gt;&lt;BR /&gt;ranuni(0)&lt;BR /&gt;is using system time as a seed . It is changed every time when you are running code .</description>
      <pubDate>Fri, 22 Apr 2022 13:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809298#M319132</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-04-22T13:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809299#M319133</link>
      <description>&lt;P&gt;Hello, Thank you for you quick reply. I know the TIME when I executed the code. Is there any chance to get it with the system time?&lt;/P&gt;&lt;P&gt;-Regards,&lt;/P&gt;&lt;P&gt;Sukumar&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 13:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809299#M319133</guid>
      <dc:creator>SukumarBalusamy</dc:creator>
      <dc:date>2022-04-22T13:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809329#M319145</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/423692"&gt;@SukumarBalusamy&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC PLAN writes the initial seed (and the final seed) to the log. In addition, you can retrieve these two seeds from automatic macro variables &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0wl5clld5bl24n1w6wm7s6sheie.htm" target="_blank" rel="noopener"&gt;SYSRANDOM and SYSRANEND&lt;/A&gt;, respectively, as shown in the log of your code (plus two %PUT statements) below:&lt;/P&gt;
&lt;PRE&gt;568   Data _null_;
569   call symputx ('Seedval', tranwrd(put(ranuni(0), best9.), '0.' , ' '));
570   run;

NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.06 seconds


571
572   proc plan seed=&amp;amp;Seedval. ;
NOTE: At the start of processing, random number seed=&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;9261594&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;.
573      factors BlockID= 50 ordered Treatment=4 random /noprint  ;
574      output out=RandList BlockID nvals=(1 to 50)
575      Treatment cvals=('Arm A' 'Arm A' 'Arm B' 'Arm B' );
576   quit;

NOTE: The data set WORK.RANDLIST has 200 observations and 2 variables.
NOTE: At the  end  of processing, random number seed=&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#FF00FF"&gt;1219503538&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;.
NOTE: PROCEDURE PLAN used (Total process time):
      real time           0.10 seconds
      cpu time            0.10 seconds


577
578   %put &amp;amp;=sysrandom;
SYSRANDOM=&lt;FONT size="4" color="#3366FF"&gt;&lt;STRONG&gt;9261594&lt;/STRONG&gt;&lt;/FONT&gt;
579   %put &amp;amp;=sysranend;
SYSRANEND=&lt;FONT size="4" color="#FF00FF"&gt;&lt;STRONG&gt;1219503538&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Apr 2022 15:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809329#M319145</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-22T15:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809336#M319150</link>
      <description>Are you trying to get this after you've run the code and need to figure out what the seed was to recreate the plan or document the process?</description>
      <pubDate>Fri, 22 Apr 2022 15:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809336#M319150</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-22T15:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809348#M319160</link>
      <description>&lt;P&gt;Thank you for the information about&amp;nbsp;%put &amp;amp;=sysrandom;&amp;nbsp; and %put &amp;amp;=sysranend; features of SAS definitely I utilize in my future codes. At present my situation I have created one Randomization schedule, but I don't know the Seed value which SAS has taken. I know the approximate time I executed this code. Is there any way to capture it.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 16:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809348#M319160</guid>
      <dc:creator>SukumarBalusamy</dc:creator>
      <dc:date>2022-04-22T16:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809351#M319163</link>
      <description>Hello, yes you are correct. The code I executed couple of months ago [08-Feb-2022 14:43] , I missed to include the code to capture the seed value. I need to document it and the question is to reproduce the list.</description>
      <pubDate>Fri, 22 Apr 2022 16:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809351#M319163</guid>
      <dc:creator>SukumarBalusamy</dc:creator>
      <dc:date>2022-04-22T16:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809354#M319166</link>
      <description>I guess you could try running it with the seed of that time, but you like need to try a few minutes after and in seconds which means trying a couple of hundred iterations to see what will match yours. Probably write a macro to loop through the times and use PROC COMPARE to compare the output you have stored with the created output. Make sure to delete the datasets in between so that you don't clog up your spaces. Not sure if it would work but something you could try.</description>
      <pubDate>Fri, 22 Apr 2022 16:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809354#M319166</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-22T16:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809383#M319183</link>
      <description>&lt;P&gt;This is an interesting, but difficult task. I don't know how exactly SAS determines the seed from "the time of day" (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1fkiqt9ygapyxn1pd1w8manlpub.htm#p0t8oarf7a3y2cn15fakwbnvcbul" target="_blank" rel="noopener"&gt;RANUNI documentation&lt;/A&gt;), but I've just figured out how you can recover the actual seed from a&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ranuni(0)&lt;/FONT&gt; random number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS Log:&lt;/P&gt;
&lt;PRE&gt;1065  data _null_; t=time(); x=ranuni(0); nextseed=x*(2**31-1); put (t x nextseed)(=best16.); run;

t=71854.3729999065 x=&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;0.03466819368055&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt; nextseed=&lt;STRONG&gt;&lt;FONT size="4" color="#FF00FF"&gt;74449379&lt;/FONT&gt;&lt;/STRONG&gt;
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.06 seconds


1066  data _null_; t=time(); x=ranuni(0); nextseed=x*(2**31-1); put (t x nextseed)(=best16.); run;

t=71854.4820001125 x=&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;0.4605221792406&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt; nextseed=988963849
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


1067  data _null_; x=ranuni( &lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;195590984&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;); put x=best16.; run;

x=&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;0.03466819368055&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.06 seconds


1068  data _null_; x=ranuni(&lt;FONT size="4" color="#000000"&gt;&lt;STRONG&gt;1764153903&lt;/STRONG&gt;&lt;/FONT&gt;); put x=best16.; run;

x=&lt;STRONG&gt;&lt;FONT size="4" color="#008000"&gt;0.4605221792406
&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The mathematical formula for the seed appears to be:&amp;nbsp;&lt;FONT face="courier new,courier" size="4"&gt;seed = mod(58743242*nextseed, 2**31-1)&lt;/FONT&gt;. (The "magic" number&amp;nbsp;&lt;FONT face="courier new,courier" size="4"&gt;58743242&lt;/FONT&gt; is the multiplicative inverse of the "multiplier"&amp;nbsp;&lt;SPAN&gt;397204094 (mentioned in the RANUNI documentation) modulo &lt;FONT face="courier new,courier" size="4"&gt;2**31-1&lt;/FONT&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the first of the two examples above you can use this formula directly in a data step:&lt;/P&gt;
&lt;PRE&gt;1080  data _null_;
1081  nextseed=&lt;STRONG&gt;&lt;FONT size="4" color="#FF00FF"&gt;74449379&lt;/FONT&gt;&lt;/STRONG&gt;;
1082  seed = mod(58743242*nextseed, 2**31-1);
1083  put seed;
1084  run;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;195590984&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;For the second example you need more sophisticated code (or just use the Windows calculator calc.exe) to obtain the seed &lt;FONT face="courier new,courier" size="4" color="#000000"&gt;&lt;STRONG&gt;1764153903&lt;/STRONG&gt;&lt;/FONT&gt;, because&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;58743242*988963849 = 58094942711058458 &amp;gt; constant('exactint')&lt;/PRE&gt;
&lt;P&gt;on a Windows system so that the precision is insufficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the difficult question is how to obtain the seed value from the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt;&amp;nbsp;value (or is &lt;FONT face="courier new,courier"&gt;datetime()&lt;/FONT&gt;&amp;nbsp;used?), e.g.:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier" size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;195590984&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;71854.3729999065&lt;/FONT&gt; and&lt;/LI&gt;
&lt;LI&gt;&lt;FONT size="4" color="#000000"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;1764153903&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt; from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;71854.4820001125&lt;/FONT&gt;.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Obviously, you must not ignore &lt;EM&gt;fractions of a second&lt;/EM&gt;&amp;nbsp;when you "&lt;SPAN&gt;loop through the times" ...&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 18:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809383#M319183</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-22T18:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809436#M319219</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Now the difficult question is how to obtain the seed value from the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt;&amp;nbsp;value (or is &lt;FONT face="courier new,courier"&gt;datetime()&lt;/FONT&gt;&amp;nbsp;used?), e.g.:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier" size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;195590984&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;71854.3729999065&lt;/FONT&gt; and&lt;/LI&gt;
&lt;LI&gt;&lt;FONT size="4" color="#000000"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;1764153903&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt; from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;71854.4820001125&lt;/FONT&gt;.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Obviously, you must not ignore &lt;EM&gt;fractions of a second&lt;/EM&gt;&amp;nbsp;when you "&lt;SPAN&gt;loop through the times" ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Addendum:&lt;/P&gt;
&lt;P&gt;It has turned out that it's even more complicated than that. In a macro loop I created (&lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;ranuni(0)&lt;/FONT&gt;) pairs and calculated the corresponding (internal) seed value. Several times successive&amp;nbsp;&lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt; values were exactly identical, yet the internal seed values (and hence the random numbers) were totally different. The first ten observations are shown below.&lt;/P&gt;
&lt;PRE&gt;Obs              time()           ranuni(0)       seed

  1    36776.9690001011    0.35282075235286    1799776034
&lt;FONT color="#993300"&gt;  2    36776.9839999676    0.87105420598344      36942890
  3    36776.9839999676    0.48406173311363    1140815067&lt;/FONT&gt;
&lt;FONT color="#0000FF"&gt;  4    36777.0000000000    0.81978151706037      94069556
  5    36777.0000000000    0.51275829529053    1348101720&lt;/FONT&gt;
&lt;FONT color="#008080"&gt;  6    36777.0150001049    0.78849600851000    1812341011
  7    36777.0150001049    0.76414637489437     910195803&lt;/FONT&gt;
&lt;FONT color="#999999"&gt;  8    36777.0309998989    0.98833351442047    1748722162
  9    36777.0309998989    0.44593092074894    2132102851&lt;/FONT&gt;
 10    36777.0469999313    0.18930490696305    2064843663&lt;/PRE&gt;
&lt;P&gt;So, the internal seed is definitely &lt;EM&gt;not&lt;/EM&gt; derived from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;datetime()&lt;/FONT&gt;&amp;nbsp;alone.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2022 11:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809436#M319219</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-23T11:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809750#M319328</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/423692"&gt;@SukumarBalusamy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello, yes you are correct. The code I executed couple of months ago [08-Feb-2022 14:43] , I missed to include the code to capture the seed value. I need to document it and the question is to reproduce the list.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/423692"&gt;@SukumarBalusamy&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sadly, I think from the results shown so far it's fairly obvious that the approximate time stamp "08-Feb-2022 14:43" is not going to give us a useful clue about the unknown seed value:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Even &lt;EM&gt;identical&lt;/EM&gt; values of the TIME() function did not imply similar internal seed values used in a &lt;FONT face="courier new,courier"&gt;ranuni(0)&lt;/FONT&gt; call.&lt;/LI&gt;
&lt;LI&gt;We don't know the exact form of the time stamp used internally by the RANUNI function when called with argument 0 &lt;EM&gt;and&lt;/EM&gt; we don't know the function used to transform the time stamp into a valid seed value between 1 and 2**31-2. (Not sure if the SAS developers would be willing to share these secrets.)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;But there is hope!&lt;/STRONG&gt; Your DATA _NULL_ step can only generate up to 10 million different seeds, which is a relatively small subset (&amp;lt;0.5%) of the set of all 2.1 billion possible seeds. Preliminary investigations that I have done indicate that there is a chance to reproduce the results from PROC PLAN &lt;EM&gt;in a DATA step&lt;/EM&gt;. Moreover, much less than your 50 randomized blocks should be sufficient to characterize a seed uniquely: With only 9 blocks we have already 6**9=10,077,696 different possible treatment combinations, i.e. more combinations than seeds. This means that the known result of, e.g., the first 9 (or possibly 7 or 8&lt;FONT face="helvetica"&gt;)&lt;/FONT&gt; blocks in dataset&amp;nbsp;&lt;SPAN&gt;RandList is likely to reduce the number of "candidate" seeds from 10 million to such a small value that it's feasible to test all of these with the complete PROC PLAN step.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So, this might be a promising strategy:&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt; Write a DATA step that runs through the 10 million potential seeds and creates the first 7 to 9 blocks in the same way PROC PLAN would do it (result: a dataset with 10 million observations).&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt; Match the resulting dataset with dataset RandList (or a dataset derived from it) to select a small number &lt;EM&gt;n&lt;/EM&gt; of candidate seeds.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;If &lt;EM&gt;n&lt;/EM&gt;&amp;gt;1, run PROC PLAN in a macro loop with &lt;EM&gt;n&lt;/EM&gt; iterations, until RandList is replicated exactly.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;SPAN&gt;Obviously, item 1 is not an easy task ... Alternatively, you could go for a brute-force approach and replace item 1 with a macro loop running 10 million PROC PLAN steps (creating only 7 to 9 blocks each, to save time and disk space). However, I don't know how long this would take to run on your hardware, even if 5 million iterations might be enough to get a hit (if you're lucky). Maybe try with, say, 10,000 iterations and then extrapolate the time.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Basically, the question is, how important it really is for you to find the unknown seed value.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 17:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809750#M319328</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-25T17:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809861#M319386</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/423692"&gt;@SukumarBalusamy&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good news! You will be able to recover your lost seed!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me first note that, with a small probability, your DATA _NULL_ step will produce an invalid seed: The BEST9. format will use scientific notation (e.g. &lt;FONT face="courier new,courier"&gt;4.657E-10&lt;/FONT&gt;) if &lt;FONT face="courier new,courier"&gt;ranuni(0)&lt;/FONT&gt; happens to be very small. PROC PLAN would then error out with a log message like&lt;/P&gt;
&lt;PRE&gt;ERROR: The value SEED = 4.657E-10 is not an integer.&lt;/PRE&gt;
&lt;P&gt;But apparently this unlikely case did not happen when you created your RandList dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Further, note that leading zeros in macro variable &lt;FONT face="courier new,courier"&gt;Seedval&lt;/FONT&gt; will be ignored by PROC PLAN. This means that if we recover a seed of, say, 1234, the true "historical" value of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Seedval&lt;/FONT&gt; might have been 1234 or 01234 or 001234 or 0001234, but this is unimportant for PROC PLAN. The probability that two &lt;EM&gt;significantly&lt;/EM&gt; different seeds produce the same PROC PLAN output (with 200 observations) is extremely small, if not zero, and the DATA step below can find all of them, if needed (see comment about the STOP statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It turned out that the DATA step that I outlined in item 1 of my previous post is so fast that we don't have to limit it to "7 to 9 blocks." Instead, we let it generate treatments &lt;EM&gt;as long as they match&lt;/EM&gt; the treatments in dataset RandList. Thus we can omit items 2 and 3 of the strategy and just write the recovered seed to the dataset or to the log. On my workstation it took &lt;EM&gt;only a few seconds&lt;/EM&gt; to recover a seed, the longest time (about 15 seconds) if the seed was 9999999, i.e., the last seed checked. Nevertheless, the DATA step also allows for partial matches with RandList (just use a smaller value for macro variable &lt;FONT face="courier new,courier"&gt;nt&lt;/FONT&gt;&amp;nbsp;and comment out the STOP statement immediately following the OUTPUT statement), which may produce more than one "candidate" seed value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create treatment format */

proc format;
value trtf
1, 2 = 'A'
3, 4 = 'B';
run;

%let c=397204094; /* "multiplier" found in RANUNI documentation */
%let d=%sysevalf(2**31-1); /* =2147483647 */
%let nt=200; /* number of treatments to be generated: 50 blocks with 4 treatments each */

/* Find "candidate" seed value(s) for PROC PLAN to reproduce (parts of) dataset RandList */

data candseeds(keep=seed);
length t $10;
/* Preparation: compute 10**k * 397204094 modulo 2**31-1, k=1, ..., 9 */
array n[9] _temporary_;
n[1]=mod(10*&amp;amp;c, &amp;amp;d);
do k=2 to 9;
  n[k]=mod(10*n[k-1], &amp;amp;d);
end;
/* Prepare assignment of 2nd and 3rd treatment in a block */
array t2[4,3]   _temporary_ (2 3 4 1 3 4 2 1 4 2 3 1);
array t3[4,4,2] _temporary_ (. . 3 4 2 4 3 2
                             3 4 . . 1 4 3 1 
                             2 4 1 4 . . 1 2
                             3 2 3 1 2 1 . .);
array ppt[&amp;amp;nt] $1 _temporary_; /* for treatments A, A, B, B generated by PROC PLAN */
array trt[&amp;amp;nt]    _temporary_; /* for treatments 1, 2, 3, 4 generated by the DATA step */
/* Read the first &amp;amp;nt treatments from RandList into array ppt */
do p=1 to &amp;amp;nt;
  set RandList(keep=treatment) point=p;
  ppt[p]=char(treatment,5); /* shorten "Arm A" to "A", etc. */
end;
/* Run through all possible seeds&amp;gt;0 */
do seed=1 to 9999999;
  m=seed;
  /* Generate the first &amp;amp;nt treatments like PROC PLAN would do it */
  do i=1 to &amp;amp;nt;
    /* Emulate RANUNI(seed) */
    t=put(m,10.);
    s=input(char(t,10), 1.)*&amp;amp;c;
    do k=1 to length(left(t))-1;
      s+input(char(t,10-k), 1.)*n[k];
    end;
    m=mod(s,&amp;amp;d);
    r=m/&amp;amp;d; /* random number between 0 and 1, computed with the RANUNI algorithm */
    /* Assign treatments based on the random number and the previous treatments in the block */
    select(mod(i,4));
      when(1) trt[i]=ceil(4*r);
      when(2) trt[i]=t2[trt[i-1],ceil(3*r)];
      when(3) trt[i]=t3[trt[i-2],trt[i-1],ceil(2*r)];
      otherwise trt[i]=10-trt[i-3]-trt[i-2]-trt[i-1]; /* = the only remaining treatment */
    end;
    if put(trt[i],trtf.) ne ppt[i] then leave; /* move on to next seed if a discrepancy was found */
  end;
  if i&amp;gt;&amp;amp;nt then do; /* i.e., no discrepancies were found */
    output; /* write "candidate" seed to dataset CANDSEEDS */
    stop; /* Remove this STOP statement if you expect more than one "candidate" seed, */
  end;    /* e.g., if &amp;amp;nt is less than the number of observations in RandList.        */
end;
stop; /* necessary because of SET statement with POINT= option */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please run the code above using your RandList dataset. The expected outcome is a single observation in dataset CANDSEEDS containing the seed value with which PROC PLAN should reproduce dataset RandList.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 13:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809861#M319386</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-26T13:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809887#M319405</link>
      <description>Impressive &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;</description>
      <pubDate>Tue, 26 Apr 2022 15:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809887#M319405</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-26T15:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Seed value used by SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809899#M319411</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; It was an exciting challenge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Luckily, the treatment assignments by PROC PLAN based on uniformly distributed random numbers in (0, 1) were pretty much straightforward (see CEIL function calls), except for some unexpected permutations, which I handled with the arrays &lt;FONT face="courier new,courier"&gt;t2&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;t3&lt;/FONT&gt;. Most importantly, the algorithm was the same for all treatment blocks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, without the simplicity of the random number generator implemented in PROC PLAN (same as in the RANUNI function, which had to be emulated in the data step) the task would have been much more difficult.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 16:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Seed-value-used-by-SAS/m-p/809899#M319411</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-26T16:30:33Z</dc:date>
    </item>
  </channel>
</rss>

