<?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: Splitting a program containing several macros to seperate files named as the macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754561#M237979</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381436"&gt;@SasStatistics&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;2 would be very nice, do you have any advice on how to do this?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, I do not personally have advice on this. Perhaps some other member of the SAS Communities has done something like this.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jul 2021 11:42:42 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-07-16T11:42:42Z</dc:date>
    <item>
      <title>Splitting a program containing several macros to seperate files named as the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754540#M237967</link>
      <description>&lt;P&gt;So far I have used %include statements to include a file containing several macros (around 100). By doing this, I can use the macros in other programs. But, I think that the standard &lt;STRONG&gt;(not sure if it is best practice?)&lt;/STRONG&gt; of including macros is to use auto call libraries. In auto call libraries, every macro should be saved in a seperate file named as the macro.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The file I included is schematically of the form:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyMacro1; 
 /* some code */ 
%mend; 

%macro Macro2; 
 /* some code */ 
%mend; 

... 
...
...

%macro AnotherMacro; 
 /* some code */ 
%mend; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any way of splitting the schematic program above into seperate files containing the specific macro and where the file is named as the macro (this would make the switch to auto call easy).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So, the first file would be called MyMacro1, the second Macro2 and so on.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 10:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754540#M237967</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-07-16T10:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a program containing several macros to seperate files named as the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754548#M237971</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381436"&gt;@SasStatistics&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there any way of splitting the schematic program above into seperate files containing the specific macro and where the file is named as the macro (this would make the switch to auto call easy).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I can think of two ways&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;manually&lt;/LI&gt;
&lt;LI&gt;write a program to parse the text&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 16 Jul 2021 10:51:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754548#M237971</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-16T10:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a program containing several macros to seperate files named as the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754560#M237978</link>
      <description>2 would be very nice, do you have any advice on how to do this?</description>
      <pubDate>Fri, 16 Jul 2021 11:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754560#M237978</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-07-16T11:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a program containing several macros to seperate files named as the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754561#M237979</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381436"&gt;@SasStatistics&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;2 would be very nice, do you have any advice on how to do this?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, I do not personally have advice on this. Perhaps some other member of the SAS Communities has done something like this.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 11:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754561#M237979</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-16T11:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a program containing several macros to seperate files named as the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754581#M237985</link>
      <description>&lt;P&gt;Really no different than any program that need to read in data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=/where/I/want/to/write/files ;
%let infile=original.sas;

data _null_;
  infile "&amp;amp;infile" dlm=' (;/'  truncover ;
  length word1 macro $32 filename $50 fullname $256 ;
  retain filename 'header.txt';
  input word1 macro ;
  if upcase(word1)=:'%MACRO' then do;
     filename = cats(lowcase(macro),'.sas');
  end;
  fullname = catx('/',"&amp;amp;path",filename);
  file out filevar=fullname ;
  put _infile_;
  if upcase(word1)='%MEND' then filename='otherlines.sas';
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So for your example you get this:&lt;/P&gt;
&lt;PRE&gt;====================
anothermacro.sas
====================
%macro AnotherMacro;
 /* some code */
%mend;

====================
macro2.sas
====================
%macro Macro2;
 /* some code */
%mend;

====================
mymacro1.sas
====================
%macro MyMacro1;
 /* some code */
%mend;

====================
otherlines.sas
====================

...
...
...
&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Jul 2021 13:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754581#M237985</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-16T13:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a program containing several macros to seperate files named as the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754596#M237995</link>
      <description>&lt;P&gt;Some questions before spending any time on parsing such a file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are ALL comments /instructions related to use of specific macros included between the %macro/ %mend? If not any parsing program to create the files would likely lose such information and you may be better off doing the separation by hand (and place the comments /instructions inside the macro code block).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there any other program statements outside of the macro definitions? If so, what should happen to those?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there any places that an entire macro may be commented out such as&lt;/P&gt;
&lt;PRE&gt;/*%macro dummy(someparm);*/
/*&amp;lt;programming statements&amp;gt;*/
/*%mend;*/&lt;/PRE&gt;
&lt;P&gt;Or is there anyplace that %macro or %mend might be in a commented out statement such as:&lt;/P&gt;
&lt;PRE&gt;%macro dummy (parm1, parm2);
/*%macro dummy(someparm);*/
&amp;lt;programming statements&amp;gt;
%mend;&lt;/PRE&gt;
&lt;P&gt;The above may happen when a version has been modified and a the old macro statement left in for documentation reasons, still in process coding or lazy programmer not removing when completed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The questions about the commented bits relate to possible "duplicate" macros found in the source file, the first one bit, or matching the correct start/end statements of a specific macro when parsing the text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 14:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754596#M237995</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-16T14:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a program containing several macros to seperate files named as the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754610#M238001</link>
      <description>&lt;P&gt;Good points.&amp;nbsp; What I tell users to do when creating autocall macro source files is to have the %MACRO statement on the first line and the %MEND statement on the last line.&amp;nbsp; If they want have a standard program header then it should be after the %MACRO statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xxx
/*----------------------------------------------------------------------
Short description
----------------------------------------------------------------------*/
(p1=P1     /* Parameter one description */
,p1=P1     /* Parameter two description */
);

/*----------------------------------------------------------------------
Usage:

one or more usage examples
------------------------------------------------------------------------
Notes:

additional information
-----------------------------------------------------------------------
History:

yyyy-mm-dd username comment
----------------------------------------------------------------------*/
%local macro parmerr ... other local macro variables;
%let macro=xxx;

%*----------------------------------------------------------------------
Validate macro parameters
-----------------------------------------------------------------------;
%parmv(P1,_req=1,_val=A B C)
%parmv(P2,_req=1)
%if (&amp;amp;parmerr) %then %goto quit;

%*----------------------------------------------------------------------
Use block style comment blocks.
To facilitate on-line browsing and printing, use only 72 columns.
-----------------------------------------------------------------------;
%quit:

%*----------------------------------------------------------------------
Abort the SAS job when errors in parameter specifications and option
ERRORABEND is turned on.
-----------------------------------------------------------------------;
%bailout(&amp;amp;parmerr)

%mend xxx;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the large file has a consistent header block before the %MACRO statement it might be possible to detect and output those, but that would be more complicated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 15:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-program-containing-several-macros-to-seperate-files/m-p/754610#M238001</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-16T15:27:11Z</dc:date>
    </item>
  </channel>
</rss>

