<?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 to Combine Files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-Combine-Files/m-p/128832#M26289</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have 3 issues I see.&lt;/P&gt;&lt;P&gt;First getting a base year. One way similar to your approach is:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%Let CurrYr = %sysfunc(year("&amp;amp;sysdate"d));&lt;/P&gt;&lt;P&gt;If SAS is restarted daily. "Year" is a data step function that requires a date value and today is a datastep function and can't be called directly in macro assignments. Another approach&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length yr $ 4 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yr = put(year(today()),f4.0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput("CurrYr",yr);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Second, the line&lt;/P&gt;&lt;P&gt;%Let PYEAR = %eval&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;(&amp;amp;FYEAR - 1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;needs a semicolon at the end;&lt;/P&gt;&lt;P&gt;Third, the line&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; color: #008080; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aaf.AcademicYear&lt;/SPAN&gt;.&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;amp;PYEAR&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; color: #008080; font-size: 10pt;"&gt;.&amp;amp;FYEAR&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;should &lt;STRONG&gt;not&lt;/STRONG&gt; have a semicolon. This is the actual text generated by the macro. with the semicolon it will generate&lt;/P&gt;&lt;P&gt;set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name2;&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, you may need an "unused" ; after the %do loop to close the SET statement depending on how you are using the combine macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jul 2013 15:55:09 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2013-07-08T15:55:09Z</dc:date>
    <item>
      <title>Macro to Combine Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-Combine-Files/m-p/128831#M26288</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please excuse a newbie question but I've searched far &amp;amp; wide and still haven't figured out how to do this simple thing. I want to create a macro variable for the current year, something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;%Let CurrYr = year(today());&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;and then use this in a macro to combine SAS files for the last 5 years:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; %Macro &lt;STRONG&gt;&lt;EM&gt;combine&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Let FYEAR = &amp;amp;curryr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Let PYEAR = %eval&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;(&amp;amp;FYEAR - 1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %DO&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; i = &lt;/SPAN&gt;&lt;STRONG style=": ; color: #008080; font-size: 10pt; font-family: Courier New;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;%TO&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #008080; font-size: 10pt; font-family: Courier New;"&gt;5&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aaf.AcademicYear&lt;/SPAN&gt;.&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;amp;PYEAR&lt;/SPAN&gt;&lt;SPAN style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;.&amp;amp;FYEAR&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Let FYEAR = %eval(&amp;amp;curryr - &amp;amp;i);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Let PYEAR = %eval&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;(&amp;amp;FYEAR - 1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %End;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;%MEND;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;So the first iteration would get the file named AcademicYear20122013 and combine it with files for the previous four years thru AcademicYear20082009.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;Thanks for any help.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 15:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-Combine-Files/m-p/128831#M26288</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2013-07-08T15:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to Combine Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-Combine-Files/m-p/128832#M26289</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have 3 issues I see.&lt;/P&gt;&lt;P&gt;First getting a base year. One way similar to your approach is:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%Let CurrYr = %sysfunc(year("&amp;amp;sysdate"d));&lt;/P&gt;&lt;P&gt;If SAS is restarted daily. "Year" is a data step function that requires a date value and today is a datastep function and can't be called directly in macro assignments. Another approach&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length yr $ 4 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yr = put(year(today()),f4.0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput("CurrYr",yr);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Second, the line&lt;/P&gt;&lt;P&gt;%Let PYEAR = %eval&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;(&amp;amp;FYEAR - 1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;needs a semicolon at the end;&lt;/P&gt;&lt;P&gt;Third, the line&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; color: #008080; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aaf.AcademicYear&lt;/SPAN&gt;.&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;amp;PYEAR&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; color: #008080; font-size: 10pt;"&gt;.&amp;amp;FYEAR&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;should &lt;STRONG&gt;not&lt;/STRONG&gt; have a semicolon. This is the actual text generated by the macro. with the semicolon it will generate&lt;/P&gt;&lt;P&gt;set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name2;&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, you may need an "unused" ; after the %do loop to close the SET statement depending on how you are using the combine macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 15:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-Combine-Files/m-p/128832#M26289</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-07-08T15:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to Combine Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-Combine-Files/m-p/128833#M26290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;BallardW,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your helpful assistance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 18:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-Combine-Files/m-p/128833#M26290</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2013-07-08T18:00:33Z</dc:date>
    </item>
  </channel>
</rss>

