<?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 Generate a list of comma separated arguments for a function using a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856427#M338391</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;suppose I want to write a macto that generates the following line of code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data smthg
    call missing(var1,var2,var3,var4)
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;my best effort is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro my_missing;
    data smtgh;    
    call missing (
       %do i=1 %to 4;
          %if i ne 4 %then
              var&amp;amp;i,;
          %else
              var&amp;amp;i;
       %end;
    );
    run;
%mend my_missing&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;when I run it I get the following error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;69 ); run;&lt;/DIV&gt;&lt;DIV class=""&gt;_&lt;/DIV&gt;&lt;DIV class=""&gt;159&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR 159-185: Null parameters for MISSING are invalid.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;I know there are different and less convoluted ways to achieve the same practical result, but I'm trying to explore the macro language and see if I can dinamically create a set of arguments for a function or a call routine when commas are required to separate each agument.&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2023 10:56:07 GMT</pubDate>
    <dc:creator>MikeFox</dc:creator>
    <dc:date>2023-01-31T10:56:07Z</dc:date>
    <item>
      <title>Generate a list of comma separated arguments for a function using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856427#M338391</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;suppose I want to write a macto that generates the following line of code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data smthg
    call missing(var1,var2,var3,var4)
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;my best effort is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro my_missing;
    data smtgh;    
    call missing (
       %do i=1 %to 4;
          %if i ne 4 %then
              var&amp;amp;i,;
          %else
              var&amp;amp;i;
       %end;
    );
    run;
%mend my_missing&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;when I run it I get the following error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;69 ); run;&lt;/DIV&gt;&lt;DIV class=""&gt;_&lt;/DIV&gt;&lt;DIV class=""&gt;159&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;ERROR 159-185: Null parameters for MISSING are invalid.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;I know there are different and less convoluted ways to achieve the same practical result, but I'm trying to explore the macro language and see if I can dinamically create a set of arguments for a function or a call routine when commas are required to separate each agument.&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 10:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856427#M338391</guid>
      <dc:creator>MikeFox</dc:creator>
      <dc:date>2023-01-31T10:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a list of comma separated arguments for a function using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856428#M338392</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420040"&gt;@MikeFox&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add the missing ampersand in the %IF condition&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;amp;&lt;/FONT&gt;&lt;/STRONG&gt;i ne 4&lt;/PRE&gt;
&lt;P&gt;and the missing semicolon of the %MEND statement and correct the typo in the dataset name. Then it will work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: In addition, I would insert&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local i;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before the DATA statement, as this is good practice to avoid name conflicts with macro variables outside the macro.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 11:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856428#M338392</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-01-31T11:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a list of comma separated arguments for a function using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856434#M338395</link>
      <description>&lt;P&gt;It's a good approach to first have some working data step code before you try and generate such code. Taking what you shared and after fixing the syntax errors this appears to work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data smthg;
  call missing(var1,var2,var3,var4);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1675164334264.png" style="width: 513px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79967i4BB1186A0523A6AA/image-dimensions/513x68?v=v2" width="513" height="68" role="button" title="Patrick_0-1675164334264.png" alt="Patrick_0-1675164334264.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you just need to get the macro syntax right so it generates the exact same data step code. Use option MPRINT to have SAS write to the SAS log what the macro generates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using in below code also option mfile as this allows to write the macro generated code to an external file ...and then I've got a data _null_ step to print this files with the SAS code that gets generated and then executed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mprint temp;
options mprint mfile;
%macro my_missing();
    data smtgh;    
    call missing (
       %do i=1 %to 4;
          %if i ne 4 %then
              var&amp;amp;i,;
          %else
              var&amp;amp;i;
       %end;
    );
    run;
%mend my_missing;
%my_missing();

data _null_;
  infile mprint;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mprint temp;
options mprint mfile;
%macro my_missing();
    data smtgh;    
    call missing (
       %do i=1 %to 4;
          %if i ne 4 %then
              var&amp;amp;i,;
          %else
              var&amp;amp;i;
       %end;
    );
    run;
%mend my_missing;
%my_missing();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And here what the macro generates that then throws the error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1675164569315.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79968iE1B6ECBDE9C45FF9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1675164569315.png" alt="Patrick_1-1675164569315.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to amend your macro so it doesn't generate this last comma.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw: If that's for some real problem you want to solve then eventually share with us the real problem. I have a suspicion there might be easier approaches to get to what you really need.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 11:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856434#M338395</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-31T11:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a list of comma separated arguments for a function using a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856443#M338400</link>
      <description>&lt;P&gt;Thanks to you and to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;for the tips. I'm not solving a real world problem, I was just messing around with the macro facility to get more comfortable with it and both your answers were very helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a good day!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 12:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-a-list-of-comma-separated-arguments-for-a-function/m-p/856443#M338400</guid>
      <dc:creator>MikeFox</dc:creator>
      <dc:date>2023-01-31T12:29:35Z</dc:date>
    </item>
  </channel>
</rss>

