<?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: Retaining Randomly Assigned Variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626019#M20322</link>
    <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/300689"&gt;@yawenyu929&lt;/a&gt;&amp;nbsp; The issue to my mind is the WANT dataset for the 1st run is fine as it assigns new random numbers for the very first run i.e your start.&lt;/P&gt;
&lt;P&gt;For the subsequent week, you want process the exisitng want with EXCEPT and additional HAVE with SET operation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The EXCEPT piece of want shall retain the same values while the additional names in&amp;nbsp; HAVE shall have the newly computed random number.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Feb 2020 22:17:02 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-02-19T22:17:02Z</dc:date>
    <item>
      <title>Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626007#M20315</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset to start that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NAME&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;&lt;P&gt;Anne&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;P&gt;Allen&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on. The number of obs doesn't really matter as it is a growing dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reporting purposes, I would like&amp;nbsp;to randomly assign either 1 or 2 to a name with a 40-60 split. 40% of name will be assigned 1 and 60% will be assigned 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NAME&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Adam&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;Anne&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Alex&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp;&lt;/P&gt;&lt;P&gt;Allen&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This part is pretty simple, but the tricky part is having each name retain the same assigned number even when new names are added to the dataset. What I mean by this is if next week, if there are two more names added, the old names should not be assigned a new number, but should keep the old number. The new names will be randomly assigned a new number:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NAME&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Adam&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;Anne&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Alex&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp;&lt;/P&gt;&lt;P&gt;Allen&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;Alfred&amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;Albert&amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried proc surveyselect, and it does the first part well, but I am having trouble getting the previous names to not get randomly assigned a number again. If anyone has any suggestions, that would be great. I am not set on using proc surveyselect, any method will do as long as it can produce the correct dataset. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 21:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626007#M20315</guid>
      <dc:creator>yawenyu929</dc:creator>
      <dc:date>2020-02-19T21:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626008#M20316</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/300689"&gt;@yawenyu929&lt;/a&gt;&amp;nbsp;Hi and welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would depend on how you add new names to your SAS data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if you can use this as a template&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name $ 1-6 Group;
infile datalines missover;
datalines;
Adam   1
Anne   2
Alex   2
Allen  1
Alfred  
Albert  
;

data want;
   set have;
   group = ifn(group=., rand('table', .6), group);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 21:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626008#M20316</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-02-19T21:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626009#M20317</link>
      <description>&lt;P&gt;A DATA step can address this.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   if group = . then group = 1 + (ranuni(12345) &amp;gt; .4);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 21:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626009#M20317</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-02-19T21:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626013#M20319</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;! Thank you for your quick reply. I see what your codes are trying to do, but I would be starting with just the Name variable, nothing else. so just:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NAME&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;&lt;P&gt;Anne&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;P&gt;Allen&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am hoping to combine the first and second part into a more efficient program. Please let me know if I can clarify anything! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 21:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626013#M20319</guid>
      <dc:creator>yawenyu929</dc:creator>
      <dc:date>2020-02-19T21:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626014#M20320</link>
      <description>&lt;P&gt;Would work even with just the Name variable as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name $ 1-6;
infile datalines missover;
datalines;
Adam  
Anne  
Alex  
Allen 
Alfred
Albert
;

data want;
   set have;
   group = ifn(group=., rand('table', .6), group);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 21:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626014#M20320</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-02-19T21:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626016#M20321</link>
      <description>&lt;P&gt;Hi, draycut! Thanks for the clarification. Your code works perfectly to assign the numbers at 40-60 split, but it doesn't retain the same assigned numbers if new names are added. So if Adam, Anne, Alex, and Allen are assigned 1, 2, 2, 1 this week, then next week after adding new names, they should still be assigned&amp;nbsp;1, 2, 2, 1. Does that help to clarify?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 22:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626016#M20321</guid>
      <dc:creator>yawenyu929</dc:creator>
      <dc:date>2020-02-19T22:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626019#M20322</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/300689"&gt;@yawenyu929&lt;/a&gt;&amp;nbsp; The issue to my mind is the WANT dataset for the 1st run is fine as it assigns new random numbers for the very first run i.e your start.&lt;/P&gt;
&lt;P&gt;For the subsequent week, you want process the exisitng want with EXCEPT and additional HAVE with SET operation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The EXCEPT piece of want shall retain the same values while the additional names in&amp;nbsp; HAVE shall have the newly computed random number.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 22:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626019#M20322</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-19T22:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626037#M20325</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/300689"&gt;@yawenyu929&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, draycut! Thanks for the clarification. Your code works perfectly to assign the numbers at 40-60 split, but it doesn't retain the same assigned numbers if new names are added. So if Adam, Anne, Alex, and Allen are assigned 1, 2, 2, 1 this week, then next week after adding new names, they should still be assigned&amp;nbsp;1, 2, 2, 1. Does that help to clarify?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Where are the new names coming from?&amp;nbsp; If you added them to the dataset with the group variable then why did you remove the values of the group variable that were already there?&lt;/P&gt;
&lt;P&gt;Are you saying you are getting a new file that some old and new names?&amp;nbsp; Just merge the two and then the same IF based logic will work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge old new;
  by name;
  if group=. then ....
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Feb 2020 01:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626037#M20325</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-20T01:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626046#M20330</link>
      <description>I'm going to say that your process is wrong. &lt;BR /&gt;You can store your data from the previous month/day somewhere. When you get your new data, assign it the new random group and then append it to your master data set that maintains the old groupings.</description>
      <pubDate>Thu, 20 Feb 2020 03:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626046#M20330</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-20T03:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626052#M20332</link>
      <description>&lt;P&gt;Below might give you some guidance.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* day 0 */
data master;
  stop;
  length name $8 group 8;
  call missing(of _all_);
run;

/* day 1 */
data names;
  set sashelp.class(keep=name obs=10);
run;

proc sql;
  create table _newNames as
  select name, ifn(rand("uniform")&amp;lt;=0.4,1,2) as group
  from
    (
      select name
      from names
      except
      select name 
      from master
    )
  ;
quit;
proc append base=master data=_newNames;
run;
proc delete data=_newnames;
run;quit;

/* day 2 */
data names;
  set sashelp.class(keep=name);
run;

proc sql;
  create table _newNames as
  select name, ifn(rand("uniform")&amp;lt;=0.4,1,2) as group
  from
    (
      select name
      from names
      except
      select name 
      from master
    )
  ;
quit;
proc append base=master data=_newNames;
run;
proc delete data=_newnames;
run;quit;


proc print data=master;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Feb 2020 05:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626052#M20332</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-20T05:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Randomly Assigned Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626265#M20366</link>
      <description>&lt;P&gt;So I'm understanding the problem better, and did as&amp;nbsp;draycut suggested. I am working around the issue of new names getting added by outputting with _[date] in the name so that the previous is not overwritten, then using that as a key for outputting only new names in the updated dataset, randomly assigning again, and merging the two datasets back together. I will have to manually change the name of the dataset I'm reading in as [file]_[date], but I can't think of a better way at the moment... Thanks everyone who took the time to answer!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 18:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Retaining-Randomly-Assigned-Variables/m-p/626265#M20366</guid>
      <dc:creator>yawenyu929</dc:creator>
      <dc:date>2020-02-20T18:27:58Z</dc:date>
    </item>
  </channel>
</rss>

