<?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: Macro &amp;quot;For Each&amp;quot; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160242#M31200</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I agree with Reeza.&amp;nbsp; I (and others) have posted approaches to split your dataset.&amp;nbsp; What we (and you) should be asking is "why am I splitting my dataset, and do I want to do so?'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 08 Nov 2014 00:08:39 GMT</pubDate>
    <dc:creator>ScottBass</dc:creator>
    <dc:date>2014-11-08T00:08:39Z</dc:date>
    <item>
      <title>Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160231#M31189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a large set of data called HIST. Each record in the HIST dataset has a period_date. I have another set of data, a table of 33 period_dates called PDATES, associated with the HIST data. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to create a macro that looks at the first date in the PDATES table and creates a separate dataset from the HIST dataset where the period_Date in the HIST table is equal to the period_Date in the PDATES table. The goal is to have 33 datasets when the macro completes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've looked at various articles online about %DO, etc, and just can't seem to translate my thoughts to code. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I appreciate any assistance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 19:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160231#M31189</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2014-11-06T19:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160232#M31190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It would help if you'd provide an example of what you call the period_dates that exist in each file.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 20:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160232#M31190</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-11-06T20:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160233#M31191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have a "large data set", why would you design a program that reads the data set 33 times?&amp;nbsp; SAS can produce all 33 data sets in a single DATA step.&amp;nbsp; Wouldn't that be a better approach?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 20:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160233#M31191</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-11-06T20:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160234#M31192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The period dates are MMDDYYYYs10. format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;03/21/2014&lt;/P&gt;&lt;P&gt;04/04/2014&lt;/P&gt;&lt;P&gt;07/18/2014&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 20:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160234#M31192</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2014-11-06T20:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160235#M31193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And you want the new files to only contain the dates specified in the other file? Or, are you looking for ranges of dates on or between the dates specified in the one file?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 20:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160235#M31193</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-11-06T20:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160236#M31194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Each data set would contain all the values from the HIST table where the period_dates are equal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example the output of period_date&amp;nbsp; 03/21/2014 could have 5345 rows (and associated columns), period_date &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;04/04/2014 could have 1255 rows (and associated columns), etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Like if I was to write&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; data EXAMPLE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set HIST;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if period_date = 03/21/2014;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 20:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160236#M31194</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2014-11-06T20:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160237#M31195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another approach is to write the sas code to write the code needed to split the HIST&amp;nbsp; data using the dates dataset &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;PDATES. Automates the writing of the code Ody suggests. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set pdates ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file "c:\SASCodeToRun" ;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line="data "||compress("hist_"||put(datefield,yymmddn8.))||" ; " ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put line;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line ="&amp;nbsp;&amp;nbsp; set HIST (where=(datefield='"||put(datefield,date9.)||"'d )) ; " ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put line;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line = "run; " ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put line;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%include("c:\SASCodeToRun");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5em; font-size: 10pt;"&gt;I suggest you review the code written in the fie before you run it ... I did not test my code .... but I use this &lt;/SPAN&gt;technique&lt;SPAN style="line-height: 1.5em; font-size: 10pt;"&gt; a lot.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 21:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160237#M31195</guid>
      <dc:creator>MumSquared</dc:creator>
      <dc:date>2014-11-06T21:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160238#M31196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Its generally not recommended to split your file up. SAS has BY group processing that is quite efficient in most circumstances. Can you explain what the next step in your process would be that you would want this separated for?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's how you'd get all data from in one file&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table selected_dates as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from table1 where date in (select date from table2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by date;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 21:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160238#M31196</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-11-06T21:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160239#M31197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to loop the data for each period_date through an existing macro, chronologically. I'm certain it's possible to do without breaking the data into chunks by just using the HIST table but I'm not familiar enough with how to write the logic to do it and haven't had much success researching it online. I figured if i had an example of breaking it out into separate datasets I could adapt that to my needs. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 13:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160239#M31197</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2014-11-07T13:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160240#M31198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you can accomplish what you want with something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select catt('if period_date=',period_date,' then output _',&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;&amp;nbsp;&amp;nbsp; put(period_date,date9.),';'),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catt('_',put(period_date,date9.))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into : selects separated by ' ',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :outlist separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from pdates&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data &amp;amp;outlist.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set hist;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;amp;selects.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 14:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160240#M31198</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-11-07T14:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160241#M31199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Download the %loop macro from &lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop.sas" title="https://github.com/scottbass/SAS/blob/master/Macro/loop.sas"&gt;SAS/loop.sas at master · scottbass/SAS · GitHub&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Download the %parmv macro from &lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas" title="https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas"&gt;SAS/parmv.sas at master · scottbass/SAS · GitHub&lt;/A&gt; (or else comment out the calls to %parmv in %loop)&lt;/P&gt;&lt;P&gt;Download the %hash_split_dataset from &lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/hash_split_dataset.sas" title="https://github.com/scottbass/SAS/blob/master/Macro/hash_split_dataset.sas"&gt;SAS/hash_split_dataset.sas at master · scottbass/SAS · GitHub&lt;/A&gt; (optional, see below)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read the macro headers - there are lots of use cases in each macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;If you're SURE PDATES has all periods, then:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: #0000c0; background: white;"&gt;sql&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;noprint&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;select&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;distinct&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; period_dates format=&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: #0000c0; background: white;"&gt;yymmddn8.&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; : periods separated &lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;by&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: blue; background: white;"&gt;" "&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; pdates;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;%put&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; &amp;amp;periods;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* should be your 33 periods ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Otherwise, use your source data to ensure you cover all the periods:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;proc &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: #0000c0; background: white;"&gt;sql &lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;noprint&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;select&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;distinct&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; period_dates format=&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: #0000c0; background: white;"&gt;yymmddn8.&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; : periods separated &lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;by&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: blue; background: white;"&gt;" "&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; hist;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;%put&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; &amp;amp;periods;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* should be your 33 periods but may differ if pdates is not in sync ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: #A0C0FF;"&gt;%macro&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; &lt;STRONG&gt;&lt;EM&gt;dsnames&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;mylib.data_&amp;amp;word&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: #A0C0FF;"&gt;%mend&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: #A0C0FF;"&gt;%macro&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; &lt;STRONG&gt;&lt;EM&gt;output&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;if period_date=input(&amp;amp;word,&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: #0000c0; background: white;"&gt;yymmdd8.&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;) then output mylib.data_&amp;amp;word;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: #A0C0FF;"&gt;%mend&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;options&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;mprint&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;loop&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;periods,mname=dsnames)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; hist;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;loop&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;periods,mname=output)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Pay attention to the absence of semi-colon in the dsnames macro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;If your large HIST dataset will fit into memory, then review the macro header for %hash_split_dataset for a way to split a dataset via the hash object.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;HTH...&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Nov 2014 00:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160241#M31199</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2014-11-08T00:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160242#M31200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I agree with Reeza.&amp;nbsp; I (and others) have posted approaches to split your dataset.&amp;nbsp; What we (and you) should be asking is "why am I splitting my dataset, and do I want to do so?'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Nov 2014 00:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160242#M31200</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2014-11-08T00:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160243#M31201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you post an excerpt from the macro with the relevant code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Given that you're constrained by the functionality of your existing macro, views may be a good option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a wild guess as to what your macro could be doing, and a possible approach.&amp;nbsp; Pretend sashelp.zipcode is a large dataset, so you want to use views for better performance.&amp;nbsp; The below code should work as is on your system, so just cut-and-paste and see if it can be modified to suit your needs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BUT, if your macro can be modified to use BY processing, that would probably perform better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: #A0C0FF;"&gt;%macro&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; my_existing_macro(data=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp; %&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* pretend this is your exising macro with some complex logic ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp; %&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* and for some unknown reason cannot use BY processing ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp; proc print data=&amp;amp;data (obs=&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: blue; background: white;"&gt;20&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: #A0C0FF;"&gt;%mend&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: #A0C0FF;"&gt;%macro&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; &lt;STRONG&gt;&lt;EM&gt;code&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp; %&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* this is a "helper" macro to create the view and call my_existing_macro ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp; data myview / view=myview;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.zipcode;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where statecode=&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: blue; background: white;"&gt;"&amp;amp;word"&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;&amp;nbsp; %&lt;STRONG&gt;&lt;EM&gt;my_existing_macro&lt;/EM&gt;&lt;/STRONG&gt;(data=myview);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: #A0C0FF;"&gt;%mend&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* create a list of items to loop over ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: #0000c0; background: white;"&gt;sql&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;noprint&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;select&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;distinct&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; statecode &lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; :mylist separated &lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;by&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: blue; background: white;"&gt;" "&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; sashelp.zipcode&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; statecode &amp;lt;= &lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: blue; background: white;"&gt;"FL"&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&amp;nbsp; %&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* to limit the output for testing ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 11.0pt; font-family: 'SAS Monospace';"&gt;&lt;STRONG&gt;%put&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt; &amp;amp;mylist;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* loop over each item in the list ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* by default the loop macro calls the macro "%code" ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;options&lt;/SPAN&gt; &lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: fuchsia; background: white;"&gt;mprint&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;loop&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;mylist)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%* the output should be a invocation of proc print ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* using the myview view, which filters for each ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* item in the list.&amp;nbsp; during each iteration of %loop, ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: black; background: white;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'SAS Monospace'; color: teal; background: white;"&gt;* that item is in the reserved macro variable &amp;amp;word ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Nov 2014 00:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160243#M31201</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2014-11-08T00:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro "For Each"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160244#M31202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all for the many replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reason I require the data to be separated is due to how it needs to be processed. The HIST data, as you might guess, is historical data. It needs to be added chronologically by period_date to an Oracle table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The existing macro for current data is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro ImportData(dir2=);&lt;/P&gt;&lt;P&gt;%let X = %sysfunc(fileexist(&amp;amp;dir2)); %put &amp;amp;X;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;X = 0 %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put ERROR: File Missing. Contact Department;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %goto exit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PROC IMPORT&lt;/P&gt;&lt;P&gt;&amp;nbsp; OUT = Employee&lt;/P&gt;&lt;P&gt;&amp;nbsp; DATAFILE = &amp;amp;dir2&lt;/P&gt;&lt;P&gt;&amp;nbsp; DBMS = xlsx Replace;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SHEET = "Test";&lt;/P&gt;&lt;P&gt;&amp;nbsp; GETNAMES = YES;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; PROC SQL;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; DELETE FROM odbc AMM.AMM_Table;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; INSERT INTO odbcAMM.AMM_Table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; (sasdatefmt =&amp;nbsp; (&lt;/P&gt;&lt;P&gt;&amp;nbsp; PERIOD_DT = 'MMDDYY10.',&lt;/P&gt;&lt;P&gt;&amp;nbsp; ACTION_DT = 'MMDDYY10.',&lt;/P&gt;&lt;P&gt;&amp;nbsp; EFFECTIVE_DT = 'MMDDYY10.',&lt;/P&gt;&lt;P&gt;&amp;nbsp; TERM_DT = 'MMDDYY10.',&lt;/P&gt;&lt;P&gt;&amp;nbsp; Load_DATE = 'MMDDYY10.'&amp;nbsp; )&amp;nbsp; )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Select&lt;/P&gt;&lt;P&gt;&amp;nbsp; MANY VARIABLES.....&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM Employee;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; connect to odbc(dsn = &amp;amp;dsnName);&lt;/P&gt;&lt;P&gt;&amp;nbsp; execute (call AMM.UPSERT_Table()) by odbc;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%exit: %mend;&lt;/P&gt;&lt;P&gt;%ImportData(dir2= file location);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Due to the logic in the call procedure [AMM.UPSERT_Table], I need to add the HIST data by period, chronologically. I won't go into the details of that but creating a macro to take the HIST data and loop through the period_dates so that I can fit it into the existing macro would save me a lot of time.That's my overall plan. If I can not figure out a way to do that I will parse out the data in the HIST table period_date by period_date and run it through this macro a section at a time. It's less elegant for sure, but would still achieve my objective.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Nov 2014 14:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-quot-For-Each-quot/m-p/160244#M31202</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2014-11-10T14:13:19Z</dc:date>
    </item>
  </channel>
</rss>

