<?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: Create a parameter from flexible number of arguments in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482740#M125100</link>
    <description>&lt;P&gt;Do it in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let k=5;
data _null_;
length param $100;
do j = 1 to &amp;amp;k;
  param = catx(',',param,'X' !! strip(put(j,best.)));
end;
call symputx('param',param);
run;
%put param=&amp;amp;param.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 31 Jul 2018 09:31:31 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-07-31T09:31:31Z</dc:date>
    <item>
      <title>Create a parameter from flexible number of arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482737#M125099</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I cannot go to all process so I will ask the question from this step only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro mmacro;&lt;BR /&gt;%do j=1 %to &amp;amp;k.;&lt;BR /&gt;&amp;amp;Xj.&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a parameter that get the value: &amp;nbsp;X1,X2,X3,X4.........................&lt;/P&gt;&lt;P&gt;(As you can see the number of arguments are not fixed and depends on value of parameter &amp;amp;k.)&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, 31 Jul 2018 09:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482737#M125099</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-07-31T09:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create a parameter from flexible number of arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482740#M125100</link>
      <description>&lt;P&gt;Do it in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let k=5;
data _null_;
length param $100;
do j = 1 to &amp;amp;k;
  param = catx(',',param,'X' !! strip(put(j,best.)));
end;
call symputx('param',param);
run;
%put param=&amp;amp;param.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jul 2018 09:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482740#M125100</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-31T09:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create a parameter from flexible number of arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482752#M125108</link>
      <description>&lt;P&gt;I'm not sure that this result would be useful.&amp;nbsp; But you can get it easily enough:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%macro mmacro;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%local j;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%global mylist;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%let mylist=X1;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;%do j=2 %to &amp;amp;k.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %let mylist = &amp;amp;mylist,X&amp;amp;j.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;************** EDITED:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Based on some of your earlier questions, it is possible you don't want X1,X2,X3, but rather the value of the macro variables instead of the names of the macro variables.&amp;nbsp; While I agree with posters that have warned you that the commas are unnecessary in almost all cases and can cause trouble later, that's just something to keep in mind.&amp;nbsp; Here is the variation that uses the values of a set of macro variables:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%macro mmacro;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%local j;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%global mylist;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%let mylist=&amp;amp;X1;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;%do j=2 %to &amp;amp;k.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %let mylist = &amp;amp;mylist,&amp;amp;&amp;amp;X&amp;amp;j.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 10:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482752#M125108</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-31T10:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a parameter from flexible number of arguments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482754#M125109</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;With a macro you could use the parmbuff option as documented here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl//en/mcrolref/69726/HTML/default/viewer.htm#p1nypovnwon4uyn159rst8pgzqrl.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl//en/mcrolref/69726/HTML/default/viewer.htm#p1nypovnwon4uyn159rst8pgzqrl.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This option is rarely used and I can't really recommend to take such an approach. Anyway: Here a code sample:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro printz/parmbuff;
   %let num=1;
   %let dsname=%scan(&amp;amp;syspbuff,&amp;amp;num,%str(%(, %)));
   %put &amp;amp;=dsname;
   %do %while(&amp;amp;dsname ne);
      proc print data=&amp;amp;dsname;
      run;
      %let num=%eval(&amp;amp;num+1);
      %let dsname=%scan(&amp;amp;syspbuff,&amp;amp;num,%str(%(, %)));
   %end;
%mend printz;
%printz(sashelp.class, sashelp.air)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternatively when using a macro just pass in the string of values to a normal parameter (a macro variable) and then parse this macro variable. Just don't use a comma as delimiter as this gets already used by the macro statement to delimit parameters so you only ask for complications using the same for your value list.&lt;/P&gt;
&lt;P&gt;Here some sample code using a blank as delimiter:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro printz(ds);
   %let num=1;
   %let dsname=%scan(&amp;amp;ds,&amp;amp;num,%str( ));
   %put &amp;amp;=dsname;
   %do %while(&amp;amp;dsname ne);
      proc print data=&amp;amp;dsname;
      run;
      %let num=%eval(&amp;amp;num+1);
      %let dsname=%scan(&amp;amp;ds,&amp;amp;num,%str( ));
   %end;
%mend printz;
%printz(sashelp.class sashelp.air)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 11:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-parameter-from-flexible-number-of-arguments/m-p/482754#M125109</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-07-31T11:01:37Z</dc:date>
    </item>
  </channel>
</rss>

