<?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 create code lines with carriage return/line break in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585044#M166764</link>
    <description>&lt;P&gt;Sounds like your macro might be generating only PART of a statement. What is called a "macro function".&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your macro is currently generating one or more full steps (proc or data) then you could convert it to generate code instead (with significant changes.)&lt;/P&gt;
&lt;P&gt;Say you had this trivial macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro example;

data x;
  set y;
  if x=1
or x=2
or x=3
  ;
run;

%mend ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could recode it to generate a data step that writes SAS code and %INCLUDE it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro example;

filename code temp;
data _null_;
  file code ;
  put 'if x=1'
    / 'or x=2'
    / 'or x=3'
    / ';'
  ;
run;

data x;
  set y;
%include code / source2 ;
run;

%mend ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2019 19:01:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-08-29T19:01:28Z</dc:date>
    <item>
      <title>How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585014#M166747</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with sas&amp;nbsp;9.04.01M1P120413&lt;/P&gt;&lt;P&gt;I have some macros that create code lines.&lt;/P&gt;&lt;P&gt;The goal is to enter a few parameters and the macro creates, for example, a bunch of "index(var"item1") or&amp;nbsp;index(var"item2")" etc.&lt;/P&gt;&lt;P&gt;However, some of these computed lines can get quite long in the log.&lt;/P&gt;&lt;P&gt;The goal would be to split them on multiple log lines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an example macro and code below.&lt;/P&gt;&lt;P&gt;The line created by the macro in the log looks like this:&lt;/P&gt;&lt;P&gt;MPRINT(MYMAC): titi=1 or titi=2 or titi=3&lt;/P&gt;&lt;P&gt;Instead I would like to see something like this:&lt;/P&gt;&lt;P&gt;MPRINT(MYMAC): titi=1&lt;/P&gt;&lt;P&gt;MPRINT(MYMAC): or titi=2&lt;/P&gt;&lt;P&gt;MPRINT(MYMAC): or titi=3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sort of like the one not created by the macro:&lt;/P&gt;&lt;P&gt;74 if titi=1&lt;BR /&gt;75 or titi=2&lt;BR /&gt;76 or titi=3&lt;BR /&gt;77 then tata=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to achieve that?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example code:&lt;/P&gt;&lt;P&gt;%macro mymac(var,val);&lt;BR /&gt;&amp;nbsp; %let i=1;&lt;BR /&gt;&amp;nbsp; %do %while(%scan(&amp;amp;val,&amp;amp;i,%str( ))^= );&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %let item=%scan(&amp;amp;val,&amp;amp;i,%str( ));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %if &amp;amp;i=1 %then %do; &amp;amp;var=&amp;amp;item %end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %do; or &amp;amp;var=&amp;amp;item %end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %let i=%eval(&amp;amp;i+1);&lt;BR /&gt;&amp;nbsp; %end;&lt;BR /&gt;%mend mymac;&lt;BR /&gt;&amp;nbsp; data titi;&lt;BR /&gt;&amp;nbsp; titi=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* ends on a single line in the log */&lt;BR /&gt;&amp;nbsp; if %mymac(titi,1 2 3) then toto=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* ends on multiple lines in the log */&lt;BR /&gt;&amp;nbsp; if titi=1&lt;BR /&gt;&amp;nbsp; or titi=2&lt;BR /&gt;&amp;nbsp; or titi=3&lt;BR /&gt;&amp;nbsp; then tata=1;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 17:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585014#M166747</guid>
      <dc:creator>tristevoix</dc:creator>
      <dc:date>2019-08-29T17:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585021#M166750</link>
      <description>&lt;P&gt;No.&lt;/P&gt;
&lt;P&gt;If that is important to you then instead of using macro logic to generate the code you could write the code to a file and then %include the file.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585021#M166750</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-29T18:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585024#M166752</link>
      <description>&lt;P&gt;Hmm... I'll see if I can manage to do that.&lt;/P&gt;&lt;P&gt;Thanks! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585024#M166752</guid>
      <dc:creator>tristevoix</dc:creator>
      <dc:date>2019-08-29T18:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585025#M166753</link>
      <description>&lt;P&gt;You might consider instead of generating&lt;/P&gt;
&lt;PRE&gt;Sort of like the one not created by the macro:

74 if titi=1
75 or titi=2
76 or titi=3

&lt;/PRE&gt;
&lt;P&gt;that you generate&lt;/P&gt;
&lt;PRE&gt;if titi in (1 2 3)&lt;/PRE&gt;
&lt;P&gt;which would likely completely remove any need for this macro as that statement is easier to put in the code than the macro call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585025#M166753</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-29T18:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585029#M166756</link>
      <description>&lt;P&gt;I suppose my choice of example is rather poor.&lt;/P&gt;&lt;P&gt;The macros I have to deal with use multiple index or tranwrd or stuff like that.&lt;/P&gt;&lt;P&gt;The example I chose is just a quick thing I can try various options with.&lt;/P&gt;&lt;P&gt;I apologize if I wasn't clear enough.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585029#M166756</guid>
      <dc:creator>tristevoix</dc:creator>
      <dc:date>2019-08-29T18:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585039#M166762</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/287320"&gt;@tristevoix&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I suppose my choice of example is rather poor.&lt;/P&gt;
&lt;P&gt;The macros I have to deal with use multiple index or tranwrd or stuff like that.&lt;/P&gt;
&lt;P&gt;The example I chose is just a quick thing I can try various options with.&lt;/P&gt;
&lt;P&gt;I apologize if I wasn't clear enough.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The results of the macro processor are helpful but creating "pretty output" is not any where in the plan. If you want pretty code use &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s suggestion of writing to a text program file. That also has the added bonus of persisting from session to session for examination or minor modifications that you may need for that last odd-ball case into code that is problematic in macro code.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585039#M166762</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-29T18:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585042#M166763</link>
      <description>&lt;P&gt;I'm trying that at the moment, but I'm having a hard time finding a way to create the file and then include it from the macro itself.&lt;/P&gt;&lt;P&gt;The macros can be used in both data steps and proc sql and that's something I'd like to keep available.&lt;/P&gt;&lt;P&gt;And I only know about file/put in a data step to write stuff to files.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585042#M166763</guid>
      <dc:creator>tristevoix</dc:creator>
      <dc:date>2019-08-29T18:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585044#M166764</link>
      <description>&lt;P&gt;Sounds like your macro might be generating only PART of a statement. What is called a "macro function".&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your macro is currently generating one or more full steps (proc or data) then you could convert it to generate code instead (with significant changes.)&lt;/P&gt;
&lt;P&gt;Say you had this trivial macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro example;

data x;
  set y;
  if x=1
or x=2
or x=3
  ;
run;

%mend ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could recode it to generate a data step that writes SAS code and %INCLUDE it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro example;

filename code temp;
data _null_;
  file code ;
  put 'if x=1'
    / 'or x=2'
    / 'or x=3'
    / ';'
  ;
run;

data x;
  set y;
%include code / source2 ;
run;

%mend ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 19:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585044#M166764</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-29T19:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585045#M166765</link>
      <description>&lt;P&gt;Then yes, it's a macro function.&lt;/P&gt;&lt;P&gt;I've still lots to learn about the proper terminology. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So, looks like I can't use the file technique, then.&lt;/P&gt;&lt;P&gt;And there seems to be no other way to achieve what I want.&lt;/P&gt;&lt;P&gt;Therefore if I can't solve my initial issue at the root then I must find a way to solve it from&amp;nbsp;the log lines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for you time, gentlemen. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 19:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585045#M166765</guid>
      <dc:creator>tristevoix</dc:creator>
      <dc:date>2019-08-29T19:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585063#M166775</link>
      <description>&lt;P&gt;Note that MPRINT() will break the lines when the code is generated by a different macro.&lt;/P&gt;
&lt;P&gt;So you could make a convoluted program that uses that fact to break up the MPRINT lines.&lt;/P&gt;
&lt;P&gt;For example by using recursion.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(varname,list);
%local words i sep;
%let words=%sysfunc(countw(&amp;amp;list,%str( )));
%if &amp;amp;words=1 %then &amp;amp;varname=&amp;amp;list ;
%else %do i=1 %to &amp;amp;words ;
  &amp;amp;sep %test(&amp;amp;varname,%scan(&amp;amp;list,&amp;amp;i,%str( )))
  %let sep=or;
%end;
%mend test;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; 83         options mprint;
 84         data x;
 85          if %test(x,1 2 3) then z=2;
 MPRINT(TEST):   x=1
 MPRINT(TEST):   or
 MPRINT(TEST):   x=2
 MPRINT(TEST):   or
 MPRINT(TEST):   x=3
 86         run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 19:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585063#M166775</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-29T19:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585168#M166823</link>
      <description>&lt;P&gt;Though I did manage to find a way to solve the issue from the log lines, I very much prefer to avoid the issue altogether.&lt;/P&gt;&lt;P&gt;And this does just that.&lt;/P&gt;&lt;P&gt;I'm happy to see there's always someone more resourceful than I am and I'm even more happy when they agree to share that resourcefulness.&lt;/P&gt;&lt;P&gt;Thank you! =D&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2019 11:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585168#M166823</guid>
      <dc:creator>tristevoix</dc:creator>
      <dc:date>2019-08-30T11:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585179#M166831</link>
      <description>&lt;P&gt;Glad you found a solution, and Tom's solution is pretty nifty!&amp;nbsp; I would just encourage you to think about the trade-offs involved in implementing it.&amp;nbsp; That is, programming is in large part about managing complexity.&amp;nbsp; I understand that you want a more easily human-readable log file, which is a good thing.&amp;nbsp; Tom's solution adds a significant amount of complexity (recursive macro : ) to the logic, and arguably makes the code itself more difficult to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it's worth considering the judgement call: whether the benefit of a log with MPRINT line breaks is worth the added complexity.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2019 12:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585179#M166831</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-08-30T12:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create code lines with carriage return/line break in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585183#M166833</link>
      <description>&lt;P&gt;A good suggestion indeed. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Maybe I should explain my reasoning a bit more.&lt;/P&gt;&lt;P&gt;My task is to create a macro that can extract the code from the log, but in such a way that all macro variables used in the code are resolved (symbolgen lines) and all macro calls are replaced with the code lines (mprint lines). The goal is to produce a code the client can run without having access to the macros and such.&lt;/P&gt;&lt;P&gt;I managed to achieve that with the first program with which I was working. However, the second program was having the split mprint lines and the&amp;nbsp;issue with such lines is that unlike standard code lines they don't start with a ! and stuff.&lt;/P&gt;&lt;P&gt;I had to find a way to put back together those split lines which I eventually did. However, it seems safer to me to not have to sew lines back together in the first place.&lt;/P&gt;&lt;P&gt;The macro I wish to update isn't itself overly complex to begin with.&lt;/P&gt;&lt;P&gt;Therefore, the added complexity seems acceptable if in the end I can more reliably put the program back together from the log.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2019 12:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-code-lines-with-carriage-return-line-break-in-a/m-p/585183#M166833</guid>
      <dc:creator>tristevoix</dc:creator>
      <dc:date>2019-08-30T12:38:49Z</dc:date>
    </item>
  </channel>
</rss>

