<?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 generated code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929098#M365572</link>
    <description>&lt;P&gt;Just to add a reason why the answer is No, when you compile a macro, it does not maintain the carriage returns in the macro code.&amp;nbsp; Carriage returns could be completely ignored, or be converted to a blank space.&amp;nbsp; This is one of the reasons you cannot use a CARDS statement inside of a macro.&amp;nbsp; For example, if you run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro me() ;
data _null_ ;
x="
hello
world
"
;
put x= ;
run ;

%let x=
hello
world 
;
%put &amp;amp;=x ;
%mend me ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You get:&lt;/P&gt;
&lt;PRE&gt;204  %me()
x=helloworld
X=hello world
&lt;/PRE&gt;</description>
    <pubDate>Mon, 20 May 2024 22:47:34 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2024-05-20T22:47:34Z</dc:date>
    <item>
      <title>macro generated code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929047#M365563</link>
      <description>&lt;P&gt;macro generated code in the log from using the MPRINT option often appears as one long stream of continuous text.&amp;nbsp; &amp;nbsp;Is there a way to retain the indentation and hard returns from the original program code?&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 14:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929047#M365563</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2024-05-20T14:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: macro generated code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929051#M365566</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9248"&gt;@Batman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;macro generated code in the log from using the MPRINT option often appears as one long stream of continuous text.&amp;nbsp; &amp;nbsp;Is there a way to retain the indentation and hard returns from the original program code?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 15:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929051#M365566</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-20T15:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro generated code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929069#M365567</link>
      <description>&lt;P&gt;While I can see a very limited use for simple macro code doing such I question the general usefulness.&lt;/P&gt;
&lt;P&gt;For example I may have code like this&amp;nbsp; to conditionally add variables into a list:&lt;/P&gt;
&lt;PRE&gt;      %if %someParam=thisvalue %then %do;
           onevarname
      %end;
     %else %if %otherparameter=thatvalue %then %do;
         othervar
    %end;
  /* other code that eventually ends the list of variables*/&lt;/PRE&gt;
&lt;P&gt;Something like this preserving hard returns would result in something that might look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;   set somedataset (keep=&amp;lt;base list of variables&amp;gt;

                 onevarname


                othervarname


   );&lt;/PRE&gt;
&lt;P&gt;with nesting of %if %then macro code pushing some results into a possibly quite ugly horizontal "alignment" by preserving different levels of indentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be easier to save the log, or possibly MFILE generated file, through something removing MPRINT text, like the source file name and such and then run the resulting text through a code formatting program.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 20:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929069#M365567</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-20T20:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: macro generated code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929081#M365568</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9248"&gt;@Batman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;macro generated code in the log from using the MPRINT option often appears as one long stream of continuous text.&amp;nbsp; &amp;nbsp;Is there a way to retain the indentation and hard returns from the original program code?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is a major concern then use some other method of code generation that creates a text file with the code so it can be run via %INCLUDE statement instead.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 18:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929081#M365568</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-20T18:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: macro generated code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929098#M365572</link>
      <description>&lt;P&gt;Just to add a reason why the answer is No, when you compile a macro, it does not maintain the carriage returns in the macro code.&amp;nbsp; Carriage returns could be completely ignored, or be converted to a blank space.&amp;nbsp; This is one of the reasons you cannot use a CARDS statement inside of a macro.&amp;nbsp; For example, if you run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro me() ;
data _null_ ;
x="
hello
world
"
;
put x= ;
run ;

%let x=
hello
world 
;
%put &amp;amp;=x ;
%mend me ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You get:&lt;/P&gt;
&lt;PRE&gt;204  %me()
x=helloworld
X=hello world
&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2024 22:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929098#M365572</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-05-20T22:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: macro generated code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929107#M365577</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9248"&gt;@Batman&lt;/a&gt;&amp;nbsp;As others already explained the answer is no. If it's about inspecting some specific case then there are some manual workarounds.&lt;/P&gt;
&lt;P&gt;Approach 1:&lt;/P&gt;
&lt;P&gt;- Write the macro generated code to an external file using the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0j3zpinabl49ln13q5f5r1t46mg.htm" target="_self"&gt;MFILE Macro System Option&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;- Using SAS Studio or EG open the file (or copy/paste the code into a code window) and use Format Code (with EG: Right click into code window gives you the menu).&lt;/P&gt;
&lt;P&gt;Approach 2:&lt;/P&gt;
&lt;P&gt;For SQL code where everything is on one line (especially in server logs) what I'm often doing is to copy/paste the SQL into Notepad++ and then use plug-in Poor Man's T-Sql Formatter&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And as a productivity tip:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Poor Man's T-Sql Formatter is also really useful if you need to write a SQL for tables with a lot of columns where you need many but not all of these columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I tend to do to reduce typing (and me misspelling column names) is to run the SQL with the SAS Feedback option and then copy/paste the transformed code from the log into Notepad++ to format and tailor it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options ps=max;
data work.test;
  array var_{1000} $1;
run;
proc sql feedback noexec;
  select t1.* from work.test t1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 04:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-generated-code/m-p/929107#M365577</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-21T04:17:20Z</dc:date>
    </item>
  </channel>
</rss>

