<?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 make a macro that does same data step for multiple data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679992#M205419</link>
    <description>Woops, it works now. I just restarted SAS EG and ran the program again. No clue what was wrong. Thank you so much! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Fri, 28 Aug 2020 11:44:00 GMT</pubDate>
    <dc:creator>niki0209</dc:creator>
    <dc:date>2020-08-28T11:44:00Z</dc:date>
    <item>
      <title>How to make a macro that does same data step for multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679979#M205412</link>
      <description>&lt;P&gt;Hello fellow SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question that might be pretty simply, but I can't find out how to do it.&lt;/P&gt;&lt;P&gt;I have a lot of data sets, one for every year. Let's say they are called:&lt;/P&gt;&lt;P&gt;data1990, data1991, data1992,...,data2019, data2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to perform the same data step on each of these without writing out 30 data steps.&lt;/P&gt;&lt;P&gt;I am thinking something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro mymacro(year);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new_data_&amp;amp;year.;&lt;/P&gt;&lt;P&gt;set data_&amp;amp;year.;&lt;/P&gt;&lt;P&gt;SomedatastepthatIneed;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do i=1990 %to 2020 %by 1;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mymacro(i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this does not work. Can someone help me perform a macro that works?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 09:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679979#M205412</guid>
      <dc:creator>niki0209</dc:creator>
      <dc:date>2020-08-28T09:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a macro that does same data step for multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679982#M205414</link>
      <description>&lt;P&gt;I would combine all datasets to one (assuming that they have the same structure), add a variable containing the year and process all in one step. But maybe that is not possible, so try something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(year);
  data new_data_&amp;amp;year.;
    set data_&amp;amp;year.;
    SomedatastepthatIneed;
  run;
%mend;
 
%macro looper;
  %local i;
  %do i=1990 %to 2020;
    %mymacro(&amp;amp;i);
  %end;
%mend;

%looper;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Aug 2020 10:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679982#M205414</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-28T10:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a macro that does same data step for multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679984#M205415</link>
      <description>&lt;P&gt;Thank you very much. When I plug your code in to my program however, it does not actually run anything and give me data sets - it merely shows me some logs.&lt;/P&gt;&lt;P&gt;Do you have any idea how that can be?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 10:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679984#M205415</guid>
      <dc:creator>niki0209</dc:creator>
      <dc:date>2020-08-28T10:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a macro that does same data step for multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679987#M205417</link>
      <description>&lt;P&gt;Posting the log as text could help, please use the "insert code" function.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 10:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679987#M205417</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-28T10:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a macro that does same data step for multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679992#M205419</link>
      <description>Woops, it works now. I just restarted SAS EG and ran the program again. No clue what was wrong. Thank you so much! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 28 Aug 2020 11:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/679992#M205419</guid>
      <dc:creator>niki0209</dc:creator>
      <dc:date>2020-08-28T11:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a macro that does same data step for multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/680042#M205436</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302884"&gt;@niki0209&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Woops, it works now. I just restarted SAS EG and ran the program again. No clue what was wrong. Thank you so much! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There are a number of fairly common mistakes people make when learning the macro language that can render a SAS session unstable. Sometimes they are unmatched quotes or parentheses/brackets/braces or missing %end or %mend.&lt;/P&gt;
&lt;P&gt;What happens is the macro processor is still looking for something to "complete" an action/compilation.&lt;/P&gt;
&lt;P&gt;In a small number of cases if you realize what you left out sometimes you can submit the proper missing code but often the practical solution is 1) save your work and 2) restart SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 15:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-that-does-same-data-step-for-multiple-data/m-p/680042#M205436</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-28T15:14:22Z</dc:date>
    </item>
  </channel>
</rss>

