<?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 Hash Question! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206399#M38359</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;When I create a hash table, I have to specify the key value, but if I want to replace the key value with a new variable created during the hash iterator process within the same data step. How do I do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the code below, I want the dataset work.temp1(highlighted in red) to be created&amp;nbsp; before it hold by "mylittlehash1" ,how do I achieve that?&lt;/P&gt;&lt;P&gt;My goal is to use one single datastep (with hash) to complete the task as shown in the code below.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data work.temp1 work.temp2;&lt;BR /&gt;attrib filename length=$1000&lt;BR /&gt;sfname length=$1000&lt;BR /&gt;key length=$1000;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;declare hash mylittlehash(dataset: 'library.want', ordered:'yes');&lt;BR /&gt;declare hiter mylittlehashter('mylittlehash');&lt;BR /&gt;mylittlehash.defineData('filename');&lt;BR /&gt;mylittlehash.defineKey('sfname');&lt;BR /&gt;mylittlehash.defineDone();&lt;BR /&gt;call missing(filename,sfname,key);&lt;/P&gt;&lt;P&gt;rc=mylittlehashter.first();&lt;BR /&gt;do until (rc ne 0);&lt;BR /&gt;perlexpression2=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");&lt;BR /&gt;if prxmatch(perlexpression2,filename) then do;&lt;BR /&gt;Key=upcase((prxposn(perlexpression2,1,filename)));&lt;BR /&gt;output work.temp1;&lt;BR /&gt;rc=mylittlehashter.next();&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;declare hash mylittlehash1(dataset: 'work.temp1', ordered:'yes', duplicate: 'r');&lt;BR /&gt;mylittlehash1.defineKey('key');&lt;BR /&gt;mylittlehash1.defineData('key');&lt;BR /&gt;mylittlehash1.defineDone();&lt;BR /&gt;end;&lt;BR /&gt;set files_found;&lt;BR /&gt; perlexpression=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");&lt;BR /&gt; if prxmatch(perlexpression,filename) then do;&lt;BR /&gt; Key=upcase((prxposn(perlexpression,1,filename)));&lt;BR /&gt; end;&lt;BR /&gt; if prxposn(perlexpression,2,filename)="Z";&lt;BR /&gt; rc=mylittlehash1.check();&lt;/P&gt;&lt;P&gt;if rc=0 then output work.temp2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Mar 2015 22:39:41 GMT</pubDate>
    <dc:creator>gyambqt</dc:creator>
    <dc:date>2015-03-19T22:39:41Z</dc:date>
    <item>
      <title>Hash Question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206399#M38359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;When I create a hash table, I have to specify the key value, but if I want to replace the key value with a new variable created during the hash iterator process within the same data step. How do I do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the code below, I want the dataset work.temp1(highlighted in red) to be created&amp;nbsp; before it hold by "mylittlehash1" ,how do I achieve that?&lt;/P&gt;&lt;P&gt;My goal is to use one single datastep (with hash) to complete the task as shown in the code below.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data work.temp1 work.temp2;&lt;BR /&gt;attrib filename length=$1000&lt;BR /&gt;sfname length=$1000&lt;BR /&gt;key length=$1000;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;declare hash mylittlehash(dataset: 'library.want', ordered:'yes');&lt;BR /&gt;declare hiter mylittlehashter('mylittlehash');&lt;BR /&gt;mylittlehash.defineData('filename');&lt;BR /&gt;mylittlehash.defineKey('sfname');&lt;BR /&gt;mylittlehash.defineDone();&lt;BR /&gt;call missing(filename,sfname,key);&lt;/P&gt;&lt;P&gt;rc=mylittlehashter.first();&lt;BR /&gt;do until (rc ne 0);&lt;BR /&gt;perlexpression2=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");&lt;BR /&gt;if prxmatch(perlexpression2,filename) then do;&lt;BR /&gt;Key=upcase((prxposn(perlexpression2,1,filename)));&lt;BR /&gt;output work.temp1;&lt;BR /&gt;rc=mylittlehashter.next();&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;declare hash mylittlehash1(dataset: 'work.temp1', ordered:'yes', duplicate: 'r');&lt;BR /&gt;mylittlehash1.defineKey('key');&lt;BR /&gt;mylittlehash1.defineData('key');&lt;BR /&gt;mylittlehash1.defineDone();&lt;BR /&gt;end;&lt;BR /&gt;set files_found;&lt;BR /&gt; perlexpression=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");&lt;BR /&gt; if prxmatch(perlexpression,filename) then do;&lt;BR /&gt; Key=upcase((prxposn(perlexpression,1,filename)));&lt;BR /&gt; end;&lt;BR /&gt; if prxposn(perlexpression,2,filename)="Z";&lt;BR /&gt; rc=mylittlehash1.check();&lt;/P&gt;&lt;P&gt;if rc=0 then output work.temp2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Mar 2015 22:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206399#M38359</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2015-03-19T22:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206400#M38360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Declare 2 hashes together within the "if _n_=1, then within your hiter loop instead of writing to "output work.temp1" you add the records to the 2nd hash "myhash2.add()".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once you finished iteration through the first hash you can delete it if you want "mylittlehash1.delete()", and should you also need "work.temp1" after the data step finished then write your 2nd hash to a table "myhash2.output(dataset:"work.temp1")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Mar 2015 23:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206400#M38360</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-03-19T23:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206401#M38361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;I have modified the code like below:&lt;/P&gt;&lt;P&gt;Is that correct?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.temp;&lt;/P&gt;&lt;P&gt;attrib filename length=$1000&lt;/P&gt;&lt;P&gt;sfname length=$1000&lt;/P&gt;&lt;P&gt;key length=$1000;&lt;/P&gt;&lt;P&gt;if _n_=1 then do;&lt;/P&gt;&lt;P&gt;declare hash mylittlehash(dataset: 'library.want(where =(_job_status="Failed"))', ordered:'yes');&lt;/P&gt;&lt;P&gt;declare hiter mylittlehashter('mylittlehash');&lt;/P&gt;&lt;P&gt;mylittlehash.defineData('filename');&lt;/P&gt;&lt;P&gt;mylittlehash.defineKey('sfname');&lt;/P&gt;&lt;P&gt;mylittlehash.defineDone();&lt;/P&gt;&lt;P&gt;call missing(filename,sfname,key);&lt;/P&gt;&lt;P&gt;declare hash mylittlehash1();&lt;/P&gt;&lt;P&gt;mylittlehash1.defineKey('key');&lt;/P&gt;&lt;P&gt;mylittlehash1.defineData('key');&lt;/P&gt;&lt;P&gt;mylittlehash1.defineDone();&lt;/P&gt;&lt;P&gt;rc=mylittlehashter.first();&lt;/P&gt;&lt;P&gt;do until (rc ne 0);&lt;/P&gt;&lt;P&gt;perlexpression2=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");&lt;/P&gt;&lt;P&gt;if prxmatch(perlexpression2,filename) then do;&lt;/P&gt;&lt;P&gt;Key=upcase((prxposn(perlexpression2,1,filename)));&lt;/P&gt;&lt;P&gt;r=mylittlehash1.add();&lt;/P&gt;&lt;P&gt;rc=mylittlehashter.next();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;set files_found;&lt;/P&gt;&lt;P&gt; perlexpression=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");&lt;/P&gt;&lt;P&gt; if prxmatch(perlexpression,filename) then do;&lt;/P&gt;&lt;P&gt; Key=upcase((prxposn(perlexpression,1,filename)));&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt; if prxposn(perlexpression,2,filename)="Z";&lt;/P&gt;&lt;P&gt; rc=mylittlehash1.check();&lt;/P&gt;&lt;P&gt;if rc=0 then output work.temp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Mar 2015 00:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206401#M38361</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2015-03-20T00:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206402#M38362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Without sample data I can't check if this works in full detail - but from what I can see the code looks pretty good. I've made a few changes to your code. I've added comments where the changes were actually important and not just cosmetic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; attrib filename length=$1000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sfname length=$1000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; key length=$1000;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash mylittlehash(dataset: 'library.want(where =(_job_status="Failed"))', ordered:'yes');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hiter mylittlehashter('mylittlehash');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=mylittlehash.defineData('filename');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=mylittlehash.defineKey('sfname');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=mylittlehash.defineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash mylittlehash1();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=mylittlehash1.defineKey('key');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=mylittlehash1.defineData('key');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=mylittlehash1.defineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(of _all_);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=mylittlehashter.first();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* keep prxparse outside of the loop or the expression will get compiled */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* for every single iteration of the loop (slow and cluttering memory)&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perlexpression2=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do until (rc ne 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if prxmatch(perlexpression2,filename) then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Key=upcase((prxposn(perlexpression2,1,filename)));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r=mylittlehash1.add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=mylittlehashter.next();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set files_found;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* same thing: compile the expression only once */&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain perlexpression;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; perlexpression=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(perlexpression,filename) then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Key=upcase((prxposn(perlexpression,1,filename)));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxposn(perlexpression,2,filename)="Z" then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mylittlehash1.check() = 0 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output work.temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Mar 2015 08:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206402#M38362</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-03-20T08:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206403#M38363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 22 Mar 2015 22:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206403#M38363</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2015-03-22T22:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206404#M38364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did this answer your question? If so then please mark the answer as correct.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2015 01:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Question/m-p/206404#M38364</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-03-23T01:05:42Z</dc:date>
    </item>
  </channel>
</rss>

