<?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: Loop through array re: lagged values until... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52637#M11114</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I've correctly kept up with the thread, you are not removing repetitive assignments.&amp;nbsp; I would think that order is irrelevant and that ALL of the assignments are duplicates.&amp;nbsp; Am I missing something?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 24 Nov 2011 00:10:28 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2011-11-24T00:10:28Z</dc:date>
    <item>
      <title>Loop through array re: lagged values until...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52632#M11109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a relatively large dataset generated using Rick Wicklin's awesome &lt;A href="http://blogs.sas.com/content/iml/2010/12/29/automating-the-great-christmas-gift-exchange/"&gt;christmas gift exchange&lt;/A&gt; program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data structure looks like this (real dataset contains 10 names):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;year Name1 Name2 Name3 Name4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2011 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2012 Abe&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2013 Sue&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Abe&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2014 Bob&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Sue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2015 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Question is:&amp;nbsp; How can I iteratively pass through the dataset, deleting records until no subsequent year assigns anyone to give a gift to the same person they were assigned to buy for the previous year?&amp;nbsp; In the above example, this would mean deleting the 2nd observation in the first pass, and then in the next pass deleting the original 3rd (now 2nd) observation, resulting in a final dataset looking like this (it's no problem if obs 1 &amp;amp; obs 3 are duplicates):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;year Name1 Name2 Name3 Name4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2011 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2014 Bob&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Sue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2015 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;I can do the first pass with the following code, but I'm having trouble figuring out the code to iterate until no more consecutive dupes exist across the 10 name variables as (until some final point) new ones will be created with each pass.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data exchange2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;set exchange;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array names (10) Name1-Name4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if names{i} = lag(names{i}) then delete;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;drop i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I realize such a procedure will likely result in dropping the vast majority of the data, which is fine since right now there are ~67,000 rows/years and none of us plan to live that long! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&amp;nbsp; Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Nov 2011 15:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52632#M11109</guid>
      <dc:creator>stonewaly</dc:creator>
      <dc:date>2011-11-22T15:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through array re: lagged values until...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52633#M11110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You probably need a macro to loop over the dataset until no more records are removed.&lt;/P&gt;&lt;P&gt;Something like this should work.&amp;nbsp; But it does not look like it yields a good solution as obs 3 is just the same as obs 1 the final dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;data have ;&lt;/P&gt;&lt;P&gt; input year (name1-name4) ($);&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;2011 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy&lt;/P&gt;&lt;P&gt;2012 Abe&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Joy&lt;/P&gt;&lt;P&gt;2013 Sue&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Abe&lt;/P&gt;&lt;P&gt;2014 Bob&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Sue&lt;/P&gt;&lt;P&gt;2015 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro winnow(in=,out=);&lt;/P&gt;&lt;P&gt;%local ndel;&lt;/P&gt;&lt;P&gt;data &amp;amp;out; set &amp;amp;in; run;&lt;/P&gt;&lt;P&gt;%do %until(&amp;amp;ndel=0);&lt;/P&gt;&lt;P&gt;&amp;nbsp; data &amp;amp;out ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if eof then call symputx('ndel',ndel);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;out end=eof;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array name (4) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to dim(name) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if name(i) = lag(name(i)) then del=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if del then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ndel+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop i del ndel;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend winnow;&lt;/P&gt;&lt;P&gt;%winnow(in=have,out=want);&lt;/P&gt;&lt;P&gt;proc print data=want width=min; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; year&amp;nbsp;&amp;nbsp;&amp;nbsp; name1&amp;nbsp;&amp;nbsp;&amp;nbsp; name2&amp;nbsp;&amp;nbsp;&amp;nbsp; name3&amp;nbsp;&amp;nbsp;&amp;nbsp; name4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2011&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Joy&lt;/P&gt;&lt;P&gt; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sue&lt;/P&gt;&lt;P&gt; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2015&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Joy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Nov 2011 16:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52633#M11110</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-11-22T16:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through array re: lagged values until...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52634#M11111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This did the trick!&amp;nbsp; No need to worry about the 3rd line being the same as the first.&amp;nbsp; That's never the case in the real data, and all that was needed was to make sure person X didn't ever get assigned to person Y in two consecutive years.&amp;nbsp; Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Nov 2011 01:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52634#M11111</guid>
      <dc:creator>stonewaly</dc:creator>
      <dc:date>2011-11-23T01:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through array re: lagged values until...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52635#M11112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi Stonewaly,&lt;/P&gt;&lt;P&gt;your code deleted muitiple records in one pass. the outcome is the same as from Tom's macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; have ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; year (name1-name4) ($);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;2011 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;2012 Abe&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;2013 Sue&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Abe&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;2014 Bob&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Sue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;2015 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; exchange2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; names (&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;4&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;) Name1-Name4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; i = &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;to&lt;/SPAN&gt; &lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;4&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; names{i} = lag(names{i}) &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;delete&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; year&amp;nbsp;&amp;nbsp;&amp;nbsp; name1&amp;nbsp;&amp;nbsp;&amp;nbsp; name2&amp;nbsp;&amp;nbsp;&amp;nbsp; name3&amp;nbsp;&amp;nbsp;&amp;nbsp; name4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2011&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2015&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Joy&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Nov 2011 19:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52635#M11112</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2011-11-23T19:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through array re: lagged values until...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52636#M11113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Linlin.&amp;nbsp; That's true for the small test dataset posted with my question, but the actual dataset contained ~67,000 records and required several passes to completely remove repetitive assignments.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Nov 2011 23:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52636#M11113</guid>
      <dc:creator>stonewaly</dc:creator>
      <dc:date>2011-11-23T23:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through array re: lagged values until...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52637#M11114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I've correctly kept up with the thread, you are not removing repetitive assignments.&amp;nbsp; I would think that order is irrelevant and that ALL of the assignments are duplicates.&amp;nbsp; Am I missing something?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2011 00:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52637#M11114</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-24T00:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through array re: lagged values until...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52638#M11115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art, my using the phrase "repetitive assignments" was probably a bit careless.&amp;nbsp; It's expected and OK to have person X assigned to person Y repeatedly over time, just not in &lt;EM&gt;consecutive &lt;/EM&gt;years.&amp;nbsp; Year-to-year assignment order only matters here to the extent that such consecutive repeats are excluded.&amp;nbsp; Because the real data is for 10 people and includes 67K records (effectively infinite permutations given the typical human lifespan), culling the vast majority of it is fine and seemed like an effective way to go when I was originally considering the problem.&amp;nbsp; Just needed help writing a macro to incorporate iteration and the appropriate stopping condition.&amp;nbsp; Tom's worked for these purposes quite well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2011 02:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52638#M11115</guid>
      <dc:creator>stonewaly</dc:creator>
      <dc:date>2011-11-24T02:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through array re: lagged values until...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52639#M11116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you care about speed ,then use Hash Table. I bet you will like it more.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have ;
 input year (name1-name4) ($);
cards;
2011 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy
2012 Abe&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Joy
2013 Sue&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Abe
2014 Bob&amp;nbsp;&amp;nbsp; Abe&amp;nbsp;&amp;nbsp; Joy&amp;nbsp;&amp;nbsp; Sue
2015 Abe&amp;nbsp;&amp;nbsp; Sue&amp;nbsp;&amp;nbsp; Bob&amp;nbsp;&amp;nbsp; Joy
;
run;
data _null_;
 if 0 then set have;
 declare hash ha(hashexp:20,dataset:'have',ordered:'A');
 declare hiter hi('ha');
&amp;nbsp; ha.definekey('year');
&amp;nbsp; ha.definedata('year','name1','name2','name3','name4');
&amp;nbsp; ha.definedone();
do until(done); 
 done=1; count=0; n=ha.num_items;
 rc=hi.first(); 
 _name1=name1;_name2=name2;_name3=name3;_name4=name4;
 do while(rc=0);
&amp;nbsp; count+1;
&amp;nbsp; rc=hi.next();&amp;nbsp; 
&amp;nbsp; if _name1 eq name1 or _name2 eq name2 or _name3 eq name3 or _name4 eq name4 then do;done=0;k=year;hi.next();leave;end;
&amp;nbsp; _name1=name1;_name2=name2;_name3=name3;_name4=name4;
&amp;nbsp; if n=count+1 then leave;
 end;
 if done eq 0 then do; rx=ha.remove(key:k); end;
end;
 ha.output(dataset:'want');
run;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2011 02:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-array-re-lagged-values-until/m-p/52639#M11116</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-11-24T02:33:39Z</dc:date>
    </item>
  </channel>
</rss>

