<?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: Assign list values to users in a loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816706#M322391</link>
    <description>&lt;P&gt;Can't thank you enough - saved me a lot of headache.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jun 2022 18:42:20 GMT</pubDate>
    <dc:creator>hporter</dc:creator>
    <dc:date>2022-06-06T18:42:20Z</dc:date>
    <item>
      <title>Assign list values to users in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816696#M322386</link>
      <description>&lt;P&gt;Hey All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 datasets. One contains around 40k account numbers (all unique), and another contains 30 users (also unique).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to distribute account numbers in a particular order to each user evenly. So that by the end of the loop, the volume of accounts with each user is as close as possible.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For simplicity assume these 2 datasets, 1 with 9 account numbers, and 1 with 3 users:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data accounts;&lt;BR /&gt;input accts;&lt;BR /&gt;cards;&lt;BR /&gt;10001&lt;BR /&gt;10002&lt;BR /&gt;10003&lt;BR /&gt;10004&lt;BR /&gt;10005&lt;BR /&gt;10006&lt;BR /&gt;10007&lt;BR /&gt;10008&lt;BR /&gt;10009&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data users;&lt;BR /&gt;input users;&lt;BR /&gt;cards;&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my final output to look like this:&lt;/P&gt;&lt;P&gt;data endResult;&lt;BR /&gt;input users accts;&lt;BR /&gt;cards;&lt;BR /&gt;1 10001&lt;BR /&gt;1 10004&lt;BR /&gt;1 10007&lt;BR /&gt;2 10002&lt;BR /&gt;2 10005&lt;BR /&gt;2 10008&lt;BR /&gt;3 10003&lt;BR /&gt;3 10006&lt;BR /&gt;3 10009&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;So that, user 1 gets the 1st account number, user 2 gets the 2nd account number, user 3 gets the 3rd account number, then the loop starts over and user 1 gets the next (in this case account number 10004) and then user 2 gets the next after that (10005) and so on and so forth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this can be done in python, and therefore I assume it can be done in SAS with a datastep, but I'm not as familiar with the programming in SAS to accomplish this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any one have any ideas? Much appreciated and thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 18:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816696#M322386</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2022-06-06T18:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign list values to users in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816699#M322388</link>
      <description>&lt;P&gt;Pretty trivial with a data step. Just use the POINT= option of the SET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data accounts;
input accts @@;
cards;
10001 10002 10003 10004 10005 10006 10007 10008 10009
;

data users;
  input users @@;
cards;
1 2 3
;

data want;
  set accounts;
  p = 1 + mod(_n_-1,nobs);
  set users point=p nobs=nobs;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1654540228632.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72018i7B1F4AAFBF56F733/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1654540228632.png" alt="Tom_0-1654540228632.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Or perhaps this method is a little simpler.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do p=1 to nobs;
    set accounts;
    set users point=p nobs=nobs;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2022 18:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816699#M322388</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-06T18:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Assign list values to users in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816706#M322391</link>
      <description>&lt;P&gt;Can't thank you enough - saved me a lot of headache.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 18:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816706#M322391</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2022-06-06T18:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Assign list values to users in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816707#M322392</link>
      <description>&lt;P&gt;You do not say if these need to be assigned &lt;STRONG&gt;randomly&lt;/STRONG&gt;. Is that actually the requirement?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 18:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-list-values-to-users-in-a-loop/m-p/816707#M322392</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-06T18:43:42Z</dc:date>
    </item>
  </channel>
</rss>

