<?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: How to use hash table macro to loop a growing code? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104994#M21884</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;based on the presence of dates in your repetition&lt;/P&gt;&lt;P&gt;I recommend&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates" title="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates"&gt;http://www.sascommunity.org/wiki/Macro_Loops_with_Dates&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/343-2013.pdf" title="http://support.sas.com/resources/papers/proceedings13/343-2013.pdf"&gt;http://support.sas.com/resources/papers/proceedings13/343-2013.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;note: you can reduce your where clause&lt;/P&gt;&lt;P&gt;from:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;months=(201203) OR months=(201204) OR months=(201205) OR months=(201206)&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;to:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;where Months between 201203 and 201206;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ron Fehd&amp;nbsp; current.or.past dates maven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Apr 2013 13:47:25 GMT</pubDate>
    <dc:creator>Ron_MacroMaven</dc:creator>
    <dc:date>2013-04-11T13:47:25Z</dc:date>
    <item>
      <title>How to use hash table macro to loop a growing code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104992#M21882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to SAS, especially for do loop etc. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset named "table" looks like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Data&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Months&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;21123&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 201203&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;24578&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 201203&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;12345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 201205&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;12346&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier;"&gt;data4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 201204&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;12678&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier;"&gt;data5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 201301&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;..&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;etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;I currently need to run some sql join as following:&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;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; create table _201204 as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select A.*, B.score &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; from table as A&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; inner join&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; scoredata as B &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; on a.id=b.id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt; WHERE months=(201203) OR months=(201204)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; create table _201205 as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select A.*, B.score &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; from table as A&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; inner join&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; scoredata as B &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; on a.id=b.id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt; WHERE months=(201203) OR months=(201204) OR months=(201205)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&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;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; create table _201206 as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select A.*, B.score &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; from table as A&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; inner join&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; scoredata as B &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; on a.id=b.id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt; WHERE months=(201203) OR months=(201204) OR months=(201205) OR months=(201206)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&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;So as time goes, the code keep growing longer and longer. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I hope to improve the code using a macro + hash table and do loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have constructed a hash table using the data from "table"&lt;/P&gt;&lt;P&gt;I referred the following global forum document, it help in someway, but I couldn't get my head round of getting a full solution.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings12/069-2012.pdf" title="http://support.sas.com/resources/papers/proceedings12/069-2012.pdf"&gt;http://support.sas.com/resources/papers/proceedings12/069-2012.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help from the community is much appreciated. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Jack &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 10:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104992#M21882</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2013-04-11T10:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use hash table macro to loop a growing code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104993#M21883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it's depends on your datasets 'table' and 'scoredata'. if both datasets are not changed any more, you should be able to know how many unique values for variable months. Assume the varialbe ID in your scoredata has unique value for each record.&lt;/P&gt;&lt;P&gt;you can try something like this&lt;/P&gt;&lt;P&gt;data _201203&amp;nbsp; _201204 _201205 _201206&amp;nbsp; /*&amp;lt;&amp;gt;, you may also use macro here to list all*/;&lt;/P&gt;&lt;P&gt;length score 8.;&lt;/P&gt;&lt;P&gt;if _n_ eq 1 then do;&lt;/P&gt;&lt;P&gt;dcl hash sc(dataset:"Scoredata");&lt;/P&gt;&lt;P&gt;sc.definekey('ID");&lt;/P&gt;&lt;P&gt;sc.definedata("Score");&lt;/P&gt;&lt;P&gt;sc.definedone();&lt;/P&gt;&lt;P&gt;call missing(score);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;set table;&lt;/P&gt;&lt;P&gt;if sc.find() ne&amp;nbsp; 0 then put "Warning: ID not found from ScoreData "&amp;nbsp; ID;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select(months);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when('201203") output _201203 _201204 _201205 _201206;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when("201204") output _201204 _201205 _201206;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when("201205") output _201205 201206 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when("201206") output _201206;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; otherwise put "Warning: Other months value -" months;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;if your dataset table keep update, I would like to suggest use Proc Append to add new to proper dataset _2012&amp;lt;&amp;gt;, rather than add to 'table' then split all the data again.&lt;/P&gt;&lt;P&gt;if there are duplicated values for ID variable in scoredata, the code above need some modifcation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 13:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104993#M21883</guid>
      <dc:creator>SUN59338</dc:creator>
      <dc:date>2013-04-11T13:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use hash table macro to loop a growing code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104994#M21884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;based on the presence of dates in your repetition&lt;/P&gt;&lt;P&gt;I recommend&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates" title="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates"&gt;http://www.sascommunity.org/wiki/Macro_Loops_with_Dates&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/343-2013.pdf" title="http://support.sas.com/resources/papers/proceedings13/343-2013.pdf"&gt;http://support.sas.com/resources/papers/proceedings13/343-2013.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;note: you can reduce your where clause&lt;/P&gt;&lt;P&gt;from:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;months=(201203) OR months=(201204) OR months=(201205) OR months=(201206)&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;to:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;where Months between 201203 and 201206;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ron Fehd&amp;nbsp; current.or.past dates maven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 13:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104994#M21884</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2013-04-11T13:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to use hash table macro to loop a growing code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104995#M21885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;forgot to mention that the "scoredata" is also monthly data. So there are loads of different copy of "scoredataMONYYYY" e.g. scoredateMar2012&lt;/P&gt;&lt;P&gt;I have now streamline the code using a macro as following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;%macro mc1(mth);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;call symput('mth2', put(input(put(&amp;amp;mth,z6.),yymmn6.),monyy7.));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;run;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; create table _&amp;amp;mth as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; select A.*, B.score&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; from table as A&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; inner join&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; scoredata&amp;amp;mth2 as B&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; on a.id=b.id&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;WHERE 201203 months &amp;amp;mth&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;mc1(201203);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;mc1(201204);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;mc1(201205);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;..&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;mc1(201303);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Now my question become how can I use a do loop to repeat the running of macro. &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I know one way is to create a hash table from the dataset "table" &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;length months best12.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;if _n_ = 1 do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;declare hash m (dataset:"table", ordered: "a");&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;rc = definekey(months);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;m.definedone();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;rc=m.output (dataset: "tab_mths");&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 18:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104995#M21885</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2013-04-11T18:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use hash table macro to loop a growing code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104996#M21886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your macro parameter consists of two parts: ccyy and mm&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Macro DateText can extract ccyy and mm from an integer of a date:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates#Macro_DateText" title="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates#Macro_DateText"&gt;http://www.sascommunity.org/wiki/Macro_Loops_with_Dates#Macro_DateText&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro Do_This&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (start=%sysfunc(mdy(3,1,2012))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,stop=%sysfunc(today())&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,interval=month&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;%do ThisDate = &amp;amp;Start %to &amp;amp;Stop;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="kw2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let&lt;/SPAN&gt; D_Begin = &lt;SPAN class="kw2"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&lt;SPAN class="kw3"&gt;intnx&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&lt;SPAN class="re0"&gt;&amp;amp;Interval&lt;/SPAN&gt;,&lt;SPAN class="re0"&gt;&amp;amp;start&lt;/SPAN&gt;,&lt;SPAN class="nu0"&gt;0&lt;/SPAN&gt;,begin&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="kw2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="kw2"&gt;%let&lt;/SPAN&gt; D_End = &lt;SPAN class="kw2"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&lt;SPAN class="kw3"&gt;intnx&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&lt;SPAN class="re0"&gt;&amp;amp;Interval&lt;/SPAN&gt;,&lt;SPAN class="re0"&gt;&amp;amp;start&lt;/SPAN&gt;,&lt;SPAN class="nu0"&gt;0&lt;/SPAN&gt;,end&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;&lt;/P&gt;&lt;P class="kw2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let ccyymm = &lt;SPAN class="kw2"&gt;%&lt;/SPAN&gt;datetext(date=&amp;amp;ThisDate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,text = &lt;SPAN class="coMULTI"&gt;%nrstr(work.&amp;amp;year-&amp;amp;mm&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="coMULTI"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="coMULTI"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put note: ccYYmm = &amp;amp;ccYYmm.;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="coMULTI"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *...;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="coMULTI"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let &amp;amp;ThisDate = %eval(&amp;amp;D_End+1);&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="coMULTI"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="coMULTI"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do_This()&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 19:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-hash-table-macro-to-loop-a-growing-code/m-p/104996#M21886</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2013-04-11T19:03:01Z</dc:date>
    </item>
  </channel>
</rss>

