<?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 write a macro with a do loop for a character variable? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345201#M63515</link>
    <description>&lt;P&gt;It's the same as your original code. It creates one file by merging the n datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Mar 2017 00:37:19 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-03-29T00:37:19Z</dc:date>
    <item>
      <title>How to write a macro with a do loop for a character variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345191#M63511</link>
      <description>&lt;P&gt;I'm trying to figure out the best way to run this program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple datasets that I'm hoping to create a macro for in order to merge. &amp;nbsp;The issue is that the number of datasets I'm merging will vary. &amp;nbsp;(i.e. all will be named test1 to testn, but the exact number that I merge at a time will differ). &amp;nbsp;I was wondering if it's possible to use a do statement in a macro for this? &amp;nbsp;I've tried the code below but it's having difficulty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO merge_sort (testnum=);&lt;BR /&gt;%DO i=1 %TO &amp;amp;testnum&lt;/P&gt;&lt;P&gt;PROC SORT DATA= test&amp;amp;i;&lt;BR /&gt;BY ID MonthYear;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%MACRO merge_transpose (dataout= testnum=)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;DATA SOURCE.&amp;amp;dataout&lt;BR /&gt;MERGE test1--&amp;amp;testnum;&lt;BR /&gt;BY ID MonthYear;&lt;BR /&gt;RUN;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have advice? &amp;nbsp;I also tried running with the I'm fairly new to macros and do-steps, so any advice is helpful. &amp;nbsp;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 23:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345191#M63511</guid>
      <dc:creator>cyoung</dc:creator>
      <dc:date>2017-03-28T23:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro with a do loop for a character variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345194#M63513</link>
      <description>&lt;P&gt;Shouldn't that be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;MERGE test1-test&amp;amp;testnum;
&lt;/PRE&gt;
&lt;P&gt;rather than:&lt;/P&gt;
&lt;PRE&gt;MERGE test1--&amp;amp;testnum;
&lt;/PRE&gt;
&lt;P&gt;i.e, only one - and the filename starting with test?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, why have two macros when you can do everything with just one. e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%MACRO merge_transpose (dataout= testnum=);
  %DO i=1 %TO &amp;amp;testnum;
     PROC SORT DATA= test&amp;amp;i;
       BY ID MonthYear;
    RUN;
  %END;
  DATA SOURCE.&amp;amp;dataout;
    MERGE test1-test&amp;amp;testnum;
    BY ID MonthYear;
  RUN;
%mend;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 23:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345194#M63513</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-28T23:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro with a do loop for a character variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345200#M63514</link>
      <description>&lt;P&gt;Thank you!! That makes sense!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though question (sorry if this is a silly one), when running the do loop for the second step- will this create 1 merged dataset for all of the sorted datasets or n merged datasets (that are just test1 and testn)?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 00:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345200#M63514</guid>
      <dc:creator>cyoung</dc:creator>
      <dc:date>2017-03-29T00:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro with a do loop for a character variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345201#M63515</link>
      <description>&lt;P&gt;It's the same as your original code. It creates one file by merging the n datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 00:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-with-a-do-loop-for-a-character-variable/m-p/345201#M63515</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-29T00:37:19Z</dc:date>
    </item>
  </channel>
</rss>

