<?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: Replace spaces in a macro parameter with line returns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705390#M216381</link>
    <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/343953" target="_blank" rel="noopener"&gt;edwolfe&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can achieve this by the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(list);
   %put LIST=*;
   %do i=1 %to %sysfunc(countw(&amp;amp;list));
      %put %scan(&amp;amp;list,&amp;amp;i);
   %end;
   %put *;
%mend test;
%test(1 2 3 4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code should produce&lt;/P&gt;
&lt;PRE&gt;LIST=*
1
2
3
4
*
&lt;/PRE&gt;
&lt;P&gt;Or, if you need to output it to an external file, you can use the following code modification:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(list);
   data _null_;
      file 'c:\temp\test.txt';
      put 'LIST=*' /
          %do i=1 %to %sysfunc(countw(&amp;amp;list));
            "%scan(&amp;amp;list,&amp;amp;i)" /
          %end;
          '*';
   run;
%mend test;
%test(1 2 3 4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Dec 2020 21:25:54 GMT</pubDate>
    <dc:creator>LeonidBatkhan</dc:creator>
    <dc:date>2020-12-11T21:25:54Z</dc:date>
    <item>
      <title>Replace spaces in a macro parameter with line returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705373#M216370</link>
      <description>&lt;DIV class="forum-subj-action"&gt;&lt;DIV class="lia-message-subject lia-component-message-view-widget-subject"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="forum-post"&gt;&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;DIV class="forum-subj-action"&gt;&lt;DIV class="lia-message-subject lia-component-message-view-widget-subject"&gt;&lt;SPAN style="font-family: inherit;"&gt;I'm writing a macro that contains a macro parameter with a list of values, and I want to print each of those values on a separate line of the output file. I've tried using TRNWRD to do this, but the spaces in the list are not being replaced with line returns.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="forum-post"&gt;&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have:&lt;/P&gt;&lt;P&gt;List=*&lt;BR /&gt;1 2 3 4&lt;BR /&gt;*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;BR /&gt;LIST=*&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the example code, in which I was trying to use TRANWRD to convert spaces to line returns, I get what I thought was the line return code instead of the line returns:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1'0D0A'x2'0D0A'x3'0D0A'x4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Code:&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%macro test(list);

%Let List2 = %sysfunc(tranwrd(&amp;amp;List,%str( ),'0D0A'x));

data _null_; 
 put
  "LIST=*" /
  "&amp;amp;List2" /
  "*"
;
run;

%mend test;
%test(1 2 3 4);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 11 Dec 2020 19:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705373#M216370</guid>
      <dc:creator>edwolfe</dc:creator>
      <dc:date>2020-12-11T19:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Replace spaces in a macro parameter with line returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705381#M216375</link>
      <description>&lt;P&gt;If it's not a problem you can do it with the call symputX() routine,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(list);

data _null_;
  call symputx("List2", tranwrd(symget('List')," ",'0D0A'x),"L");
run;

data _null_;
 x = "&amp;amp;list2."; 
 put
  "LIST=*" /
  "&amp;amp;List2" /
  "*" /
  x= $hex32.
;
run;

%mend test;
%test(1 2 3 4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but don't expect to see "new lines" in the log, SAS ignores them in the log. You have to write it down to external file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(list);

data _null_;
  call symputx("List2", tranwrd(symget('List')," ",'0D0A'x),"L");
run;

filename f "%sysfunc(pathname(work))/text.txt";
filename f list;

data _null_;
 file f;
 x = "&amp;amp;list2."; 
 put
  "LIST=*" /
  "&amp;amp;List2" /
  "*" /
  x= $hex32.
;
run;

data _null_;
  infile f;
  input;
  put _N_= "**" _infile_;
run;

%mend test;
%test(1 2 3 4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;[EDIT:]&lt;/P&gt;
&lt;P&gt;This technical note my also help:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/36/916.html" target="_blank"&gt;https://support.sas.com/kb/36/916.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 20:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705381#M216375</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-12-11T20:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replace spaces in a macro parameter with line returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705390#M216381</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/343953" target="_blank" rel="noopener"&gt;edwolfe&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can achieve this by the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(list);
   %put LIST=*;
   %do i=1 %to %sysfunc(countw(&amp;amp;list));
      %put %scan(&amp;amp;list,&amp;amp;i);
   %end;
   %put *;
%mend test;
%test(1 2 3 4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code should produce&lt;/P&gt;
&lt;PRE&gt;LIST=*
1
2
3
4
*
&lt;/PRE&gt;
&lt;P&gt;Or, if you need to output it to an external file, you can use the following code modification:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(list);
   data _null_;
      file 'c:\temp\test.txt';
      put 'LIST=*' /
          %do i=1 %to %sysfunc(countw(&amp;amp;list));
            "%scan(&amp;amp;list,&amp;amp;i)" /
          %end;
          '*';
   run;
%mend test;
%test(1 2 3 4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 21:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705390#M216381</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2020-12-11T21:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Replace spaces in a macro parameter with line returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705407#M216393</link>
      <description>&lt;P&gt;I would strongly advise against adding printing controls in to macro parameters. You are adding complexity to your processing logic which isn't useful and could make it difficult to maintain.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51532"&gt;@LeonidBatkhan&lt;/a&gt;'s approach is way better.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 22:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-spaces-in-a-macro-parameter-with-line-returns/m-p/705407#M216393</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-11T22:33:01Z</dc:date>
    </item>
  </channel>
</rss>

