<?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 Pre-Labor Day Coding Challenge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60191#M13001</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In a recent thread ( &lt;A _jive_internal="true" href="https://communities.sas.com/message/104261#104261"&gt;http://communities.sas.com/message/104261#104261&lt;/A&gt; ) the OP had records with four variables and, if I correctly understood the question, wanted to know if one of the entries had been used previously and if so assign the same household # that had been used before and, if not, to increment the total households by 1 and assign it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, I fully realize that there are a number of solutions to such a problem, but many require skills that I think are currently beyond most SAS users' understanding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus, I have an alternative approach that I don't know is even doable, i.e., I wouldn't know how to do it in the way that I envision.&amp;nbsp; Proc Format would be an easy way to have a lookup table that most SAS users could relate to.&amp;nbsp; Can a format be created dynamically?&amp;nbsp; That is, starting with an empty format, check the first record and if no match was found in the format, increment a counter and assign the four entries to the format with the incremented counter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, for the next record, test the values with the format, assign the household id if found and, if not, increment the counter and add the new entries to the format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus the challenge: is that doable and, if so, provide a working example using the 100+ record dataset that the OP provided in the above mentioned thread.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Sep 2011 12:59:16 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2011-09-02T12:59:16Z</dc:date>
    <item>
      <title>Pre-Labor Day Coding Challenge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60191#M13001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In a recent thread ( &lt;A _jive_internal="true" href="https://communities.sas.com/message/104261#104261"&gt;http://communities.sas.com/message/104261#104261&lt;/A&gt; ) the OP had records with four variables and, if I correctly understood the question, wanted to know if one of the entries had been used previously and if so assign the same household # that had been used before and, if not, to increment the total households by 1 and assign it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, I fully realize that there are a number of solutions to such a problem, but many require skills that I think are currently beyond most SAS users' understanding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus, I have an alternative approach that I don't know is even doable, i.e., I wouldn't know how to do it in the way that I envision.&amp;nbsp; Proc Format would be an easy way to have a lookup table that most SAS users could relate to.&amp;nbsp; Can a format be created dynamically?&amp;nbsp; That is, starting with an empty format, check the first record and if no match was found in the format, increment a counter and assign the four entries to the format with the incremented counter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, for the next record, test the values with the format, assign the household id if found and, if not, increment the counter and add the new entries to the format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus the challenge: is that doable and, if so, provide a working example using the 100+ record dataset that the OP provided in the above mentioned thread.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Sep 2011 12:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60191#M13001</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-09-02T12:59:16Z</dc:date>
    </item>
    <item>
      <title>Pre-Labor Day Coding Challenge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60192#M13002</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art.T&lt;/P&gt;&lt;P&gt;OP not only want one of the entries had been used previously ,but also been used afterwards.&lt;/P&gt;&lt;P&gt;I do not think proc format can do it, because it is static not dynamic. And You should exclude the current obs and &lt;/P&gt;&lt;P&gt;blank , tab character ..... such invisible character.&lt;/P&gt;&lt;P&gt;Because OP 's variables are all character ,It make more complex for comparing the character.&lt;/P&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>Fri, 02 Sep 2011 13:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60192#M13002</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-09-02T13:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Pre-Labor Day Coding Challenge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60193#M13003</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a good Labour Day weekend, Dr. Art, from a fellow Torontonian.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These connected subgraph problems happens in householding a lot.&amp;nbsp; There are commercial software that does this, but if one can't afford the cost, then reinventing the hammer is necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a macro solution from a ways back that works, but not via PROC FORMAT.&amp;nbsp; Thought I'd just throw it here for fun.&amp;nbsp; As for the idea of dynamic lookup, HASH tables probably work better, but looks more daunting to the novice programmer.&amp;nbsp; Perhaps Ksharp can provide working code on that &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Sep 2011 14:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60193#M13003</guid>
      <dc:creator>DLing</dc:creator>
      <dc:date>2011-09-02T14:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Pre-Labor Day Coding Challenge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60194#M13004</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm going to look at your code later this afternoon.&amp;nbsp; Ksharp did provide a response to the thread that originally got me thinking about this, involving a hash of course, but I found that the code didn't correctly address the OP's requirements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I modified it myself and I think that the following works.&amp;nbsp; I definitely have to learn more about using a hash to solve problems like this.&amp;nbsp; I originally attempted to build a datastep solution, using call execute to invoke a macro that called proc format but, as expected, the calls to proc format had to wait until after the datastep which made them useless for the task.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My modified version of Ksharp's code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile cards dsd dlm='|' truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input (pan1 add1 pan2 pan3) (: $40.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;M5669K|4HH5BFWBBMBY48Y7P8S|P5P8YBBMBY48Y7P8S0005D|&lt;/P&gt;&lt;P&gt;I2175Q|P5P8YBBMBY48Y7P8S0005D||&lt;/P&gt;&lt;P&gt;S1495P|8BWP_Y8V3MYVWBBMBBMB||&lt;/P&gt;&lt;P&gt;G4909P|WN8Y4YFN48FYP884P83Y4||&lt;/P&gt;&lt;P&gt;|S1495P||&lt;/P&gt;&lt;P&gt;S0560L|488Y8N8N8H-K56H4YP8P||&lt;/P&gt;&lt;P&gt;F0994B|R8YPF8Y4P-0BWP8BBMBY||&lt;/P&gt;&lt;P&gt;H6408L|HICPM4BBPWFP4WV4MP8YBB||&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (keep=pan1 pan2 pan3 add1 household);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ eq 1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash ha(hashexp: 16);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ha.definekey('key');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ha.definedata('hhold');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ha.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array _house{*} $ 40 pan1--pan3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(_house);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; key=_house{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(hhold);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=ha.find();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rc=0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; household=hhold;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leave;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if not found then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; household=n;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do j=1 to dim(_house);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not missing(_house{j}) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key=_house{j};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hhold=household;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ha.replace();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Sep 2011 14:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60194#M13004</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-09-04T14:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Pre-Labor Day Coding Challenge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60195#M13005</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My code is provided for "entertainment value".&amp;nbsp; It was written many moons ago, long before hash tables were available.&amp;nbsp; It just shows when needs arise, people find ways to solve it regardless of whether it is the right way, the elegant way, or not.&amp;nbsp; Need to get stuff done is a very powerful motivator. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Sep 2011 13:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60195#M13005</guid>
      <dc:creator>DLing</dc:creator>
      <dc:date>2011-09-06T13:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Pre-Labor Day Coding Challenge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60196#M13006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And I was indeed quite entertained!&amp;nbsp; I didn't post my own solution because it turned out to be far too sloppy given the availability of hash tables.&amp;nbsp; What I did was take two passes thru the data and, like you, in a macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first pass was actually N passes, reading one record each time and appending the results to the format. Then a second pass just looking up the formatted values.&amp;nbsp; It worked, but not an approach I would recommend today.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I totally agree, though, motivation is an extremely powerful motivator and sometimes results in capabilities we didn't realize we could achieve.&amp;nbsp; Since you are going to be at the September 16th TASS (Toronto Area SAS Society) meeting, you'll get to see one of my examples of just such an effort.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Sep 2011 13:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pre-Labor-Day-Coding-Challenge/m-p/60196#M13006</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-09-06T13:29:31Z</dc:date>
    </item>
  </channel>
</rss>

