<?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: Using %macro to generate programs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433447#M281863</link>
    <description>&lt;P&gt;For what purpose?&amp;nbsp; SAS Base is designed to be extremely flexible, hence anything you do is going to limit that.&amp;nbsp; Macro is&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; a replacement for Base SAS programming!!&amp;nbsp; I can't stress this enough, the cause of almost all programming mistakes, problems, and lack of robustness is due to people jumping straight into macro programming, not really understanding what its purpose is, or that Base can do things far simpler and more robustly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The usual steps are:&lt;/P&gt;
&lt;P&gt;Write a program using Base SAS&lt;/P&gt;
&lt;P&gt;Identify sections which repeat either in this code or across code.&lt;/P&gt;
&lt;P&gt;These sections can then be extracted and macrotised following a different set of documentation and validation process and then called in the main program.&lt;/P&gt;
&lt;P&gt;I am 99% certain what you are attempting will not work, or will cause you far more than just writing the program in the first place.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2018 09:52:28 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-02-02T09:52:28Z</dc:date>
    <item>
      <title>Using %macro to generate programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433441#M281862</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;&lt;BR /&gt;I would like to automate creating base to most of my programs by&amp;nbsp;using macro that outputs code ready to use, then write it down to .txt file.&lt;BR /&gt;The problem is that (as i have found in docs) macro facility resolving tokens do not consider white marks (suchs as enter as brake line).&lt;BR /&gt;I've started from easiest version:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;%macro generator;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a=5;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;run;&lt;BR /&gt;%mend generator;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;file ".../readyPGM.txt";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;put "%generator";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;The output obviously is like:&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;data _null_;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;a=5;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Is there any workaround to include break lines?&amp;nbsp;&lt;BR /&gt;Thank you in advance for any tips and all useful opinions.&lt;BR /&gt;&lt;BR /&gt;Lukas&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 09:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433441#M281862</guid>
      <dc:creator>LukaszKul</dc:creator>
      <dc:date>2018-02-02T09:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using %macro to generate programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433447#M281863</link>
      <description>&lt;P&gt;For what purpose?&amp;nbsp; SAS Base is designed to be extremely flexible, hence anything you do is going to limit that.&amp;nbsp; Macro is&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; a replacement for Base SAS programming!!&amp;nbsp; I can't stress this enough, the cause of almost all programming mistakes, problems, and lack of robustness is due to people jumping straight into macro programming, not really understanding what its purpose is, or that Base can do things far simpler and more robustly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The usual steps are:&lt;/P&gt;
&lt;P&gt;Write a program using Base SAS&lt;/P&gt;
&lt;P&gt;Identify sections which repeat either in this code or across code.&lt;/P&gt;
&lt;P&gt;These sections can then be extracted and macrotised following a different set of documentation and validation process and then called in the main program.&lt;/P&gt;
&lt;P&gt;I am 99% certain what you are attempting will not work, or will cause you far more than just writing the program in the first place.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 09:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433447#M281863</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-02T09:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using %macro to generate programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433449#M281864</link>
      <description>&lt;P&gt;The macro facilty is designed to create &lt;EM&gt;transient, dynamic&lt;/EM&gt; code that is supposed to &lt;EM&gt;work&lt;/EM&gt; but &lt;STRONG&gt;&lt;EM&gt;not supposed to be read&lt;/EM&gt;&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't abuse it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you trying to achieve that isn't already solved by keyboard macros in EG or the tasks in EG and SAS Studio (from where you can fetch the created code and save it as .sas files anyway)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 09:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433449#M281864</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-02T09:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using %macro to generate programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433452#M281865</link>
      <description>&lt;P&gt;Thanks for you reply &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I totally understand your point, on some extent jumping straight into macros can be a really bad practice.&lt;BR /&gt;&lt;BR /&gt;As i have mentioned, what i want to achieve is to automate some basic steps that im going to use across different projects. Applying some conditional processing (not very sophisticated, just few parameters to change names/places of outputs) would really improve my programming process and also save some time. Most important sections in code cant be generates as they differ across task, but basic set-up like generating header, some dates to keep track on project etc. could be.&amp;nbsp;&lt;BR /&gt;Is this approach incorrect?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 10:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433452#M281865</guid>
      <dc:creator>LukaszKul</dc:creator>
      <dc:date>2018-02-02T10:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using %macro to generate programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433455#M281866</link>
      <description>&lt;P&gt;Then you don't need to write to files. Follow the standard macro development process:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;create code that solves a single instance of your issue&lt;/LI&gt;
&lt;LI&gt;identify parts of that code that need to be flexible&lt;/LI&gt;
&lt;LI&gt;replace those with macro variables, and set the macro vars manually&lt;/LI&gt;
&lt;LI&gt;once that works, wrap into a macro, and supply the macro vars as parameters in the %macro statement&lt;/LI&gt;
&lt;LI&gt;add macro logic (if necessary) to create derived macro values from the parameters&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;After that, use the macro anywhere in your programs where needed. Consider storing such macros in the autocall library, or in one of the autoexec locations that SAS provides.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 10:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433455#M281866</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-02T10:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using %macro to generate programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433456#M281867</link>
      <description>&lt;P&gt;Perhaps not incorrect, just maybe not described quite right.&amp;nbsp; If you have code that operates on various projects, and has some parameters, then just use and include file which contains your code and set a macro variable in your project specific code.&amp;nbsp; For instance, say I want to print sashelp.class for ABC1234, but for ABC2345 I want to print sashelp.cars:&lt;/P&gt;
&lt;P&gt;Include file:&lt;/P&gt;
&lt;PRE&gt;proc print data=sashelp.&amp;amp;study_dataset.;
run;&lt;/PRE&gt;
&lt;P&gt;Study ABC1234 program:&lt;/P&gt;
&lt;PRE&gt;%let study_data=class;

%include "include_file.sas";

data somethingelse...&lt;/PRE&gt;
&lt;P&gt;Study ABC2345:&lt;/P&gt;
&lt;PRE&gt;%let study_data=cars;

%include "include_file.sas";

data somethingelse...&lt;/PRE&gt;
&lt;P&gt;So the generic part of the code is written once in one file then include by the other two programs with them supplying their parameter.&amp;nbsp; You could of course also macrotise the include file, and then call the macro from each of those programs also.&lt;/P&gt;
&lt;P&gt;So from your given example, write the basic steps in one file or macro, then call from the others with a parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not quite as I had read your post at first and makes far more sense&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 10:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433456#M281867</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-02T10:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using %macro to generate programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433458#M281868</link>
      <description>&lt;P&gt;That's a different view that i did not think about &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Changes perspective, i'm definitely gonna rethink whole process using that &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Case closed, thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 10:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-to-generate-programs/m-p/433458#M281868</guid>
      <dc:creator>LukaszKul</dc:creator>
      <dc:date>2018-02-02T10:19:14Z</dc:date>
    </item>
  </channel>
</rss>

