<?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: Retaining the indentation, while generating Macro code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527527#M143828</link>
    <description>&lt;P&gt;1. The macro language is a text-manipulation language. It normally left justifies text values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let a=1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;is the same as&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let a=&amp;nbsp; &amp;nbsp; 1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You should not a get a one-line result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
filename mprint "%sysfunc(pathname(WORK))\mfile.sas";

options mfile mprint nomlogic;

%macro genmacro( vlist, table, filter);
  data T;   X=1; 
  proc sql;
    select   1
    from T;   quit;
%mend;        
%genmacro;

data t; 
  infile mprint;
  input; 
  put _infile_; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;generates:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data T;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;X=1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;select 1 from T;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I suspect you might generating Unix files and reading them using Windows.&lt;/P&gt;
&lt;P&gt;Look up the TERMSTR option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jan 2019 21:51:01 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-01-15T21:51:01Z</dc:date>
    <item>
      <title>Retaining the indentation, while generating Macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527232#M143695</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I a trying to get the final code after all the macro variables are resolved. I am using Mfile and Mprint options of the sas to get the generated code and store it in my local system.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename mprint '........\.mfile.sas';&lt;/P&gt;&lt;P&gt;options mfile mprint macrogen mlogic;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro genmacro( vlist, table, filter);&lt;/P&gt;&lt;P&gt;select&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;vlist&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;amp;table&lt;/P&gt;&lt;P&gt;where&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;amp;filter&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the generated code (a .sas file named: mfile.sas) gets stored at the local machine and entire code is printed in one single line like one string. This can be consumed if the code is small, but if the code is very large then it's very hard for user to understand this and make sense out of it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to get the indentation same as the SQL codes written inside the macro function? Please help me with this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for you time and help.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 07:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527232#M143695</guid>
      <dc:creator>DK_0808</dc:creator>
      <dc:date>2019-01-15T07:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining the indentation, while generating Macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527527#M143828</link>
      <description>&lt;P&gt;1. The macro language is a text-manipulation language. It normally left justifies text values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let a=1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;is the same as&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let a=&amp;nbsp; &amp;nbsp; 1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You should not a get a one-line result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
filename mprint "%sysfunc(pathname(WORK))\mfile.sas";

options mfile mprint nomlogic;

%macro genmacro( vlist, table, filter);
  data T;   X=1; 
  proc sql;
    select   1
    from T;   quit;
%mend;        
%genmacro;

data t; 
  infile mprint;
  input; 
  put _infile_; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;generates:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data T;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;X=1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;select 1 from T;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I suspect you might generating Unix files and reading them using Windows.&lt;/P&gt;
&lt;P&gt;Look up the TERMSTR option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 21:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527527#M143828</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-01-15T21:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining the indentation, while generating Macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527529#M143829</link>
      <description>&lt;P&gt;oh I see what you are saying, the select clause is on one line.&lt;/P&gt;
&lt;P&gt;I guess you have to post process the file and -for example- add a CR before commas and keywords.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 21:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527529#M143829</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-01-15T21:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining the indentation, while generating Macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527536#M143831</link>
      <description>&lt;P&gt;Thanks for the response. This is helpful. I will post in case of any concerns.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 22:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527536#M143831</guid>
      <dc:creator>DK_0808</dc:creator>
      <dc:date>2019-01-15T22:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining the indentation, while generating Macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527542#M143833</link>
      <description>&lt;P&gt;This might get you started:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro genmacro( vlist, table, filter);
  data T;     X=1; 
  proc sql;
    select   1 ,1
    from T, T where 1;   quit;
%mend;        
%genmacro;

data _null_; 
  infile mprint lrecl=32000 pad;
  file  "%sysfunc(pathname(WORK))\mfile.sas" lrecl=32000;
  input X $32000.; 
  L=length(X);                                          
  if X =: 'select ' then 
    do until(POS=0);
      POS=prxmatch('/ (from|inner|left|right|full|union|intersect|except|where|on|group by|having|order by)/',X);
      if POS then do; 
        put X $varying32000. POS;
        X=substr(X,POS+1);
      end;
      else put X ;    
    end;
  else put X $varying32000. L; 
run;

data _null_;
  infile "%sysfunc(pathname(WORK))\mfile.sas" ;
  input; 
  put _infile_; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data T;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;X=1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;select 1 ,1 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;from T, T &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;where 1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 22:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-the-indentation-while-generating-Macro-code/m-p/527542#M143833</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-01-15T22:39:49Z</dc:date>
    </item>
  </channel>
</rss>

