<?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 dynamic suffix variable name and assign it to macro ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320086#M70437</link>
    <description>&lt;P&gt;The solution will depend a bit on how you actually get to this value of 'n' but the way you've asked the question you could go for a function style macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro create_list(basename,n);
  %local _var;
  %if &amp;amp;n&amp;gt;0 %then %let _var=&amp;amp;basename.1;
  %do i=2 %to &amp;amp;n;
    %let _var=&amp;amp;_var,&amp;amp;basename&amp;amp;i;
  %end;
  &amp;amp;_var
%mend;

%let variable=%create_list(x,6);

%put &amp;amp;=variable;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Dec 2016 02:07:37 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2016-12-20T02:07:37Z</dc:date>
    <item>
      <title>How to create dynamic suffix variable name and assign it to macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320083#M70434</link>
      <description>&lt;P&gt;&amp;nbsp;I'm trying to create a variable list to pass it to a function. Right now I'm creating it manually for instance if n = 5, I have to create x1,x2,x3,x4,x5 seperated by comma, if n = 6 then I have to create x1,x2,x3,x4,x5,x6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n = 5;&lt;/P&gt;
&lt;P&gt;%let variable = x1,x2,x3,x4,x5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n=6;&lt;/P&gt;
&lt;P&gt;%let variable = x1,x2,x3,x4,x5,x6;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my question is &amp;nbsp;how to create "variable" macro automatically depening on the n value specified?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2016 01:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320083#M70434</guid>
      <dc:creator>Forecaster</dc:creator>
      <dc:date>2016-12-20T01:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix variable name and assign it to macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320084#M70435</link>
      <description>&lt;P&gt;run next lines under a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n=5;&lt;/P&gt;
&lt;P&gt;%let varables=;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let variables = &amp;amp;variables.x&amp;amp;i ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %if i &amp;lt; &amp;amp;n %then %let vaiables = &amp;amp;variables,;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%put VAEIABLES= &amp;amp;variables;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2016 01:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320084#M70435</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-20T01:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix variable name and assign it to macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320085#M70436</link>
      <description>%let n=5;&lt;BR /&gt;%let variable=x;&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;do i=1 to &amp;amp;n;&lt;BR /&gt;variable=cats("&amp;amp;variable",put(i,best.));&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select variable into :varlist separated by ',' from have;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;varlist;</description>
      <pubDate>Tue, 20 Dec 2016 02:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320085#M70436</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-12-20T02:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix variable name and assign it to macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320086#M70437</link>
      <description>&lt;P&gt;The solution will depend a bit on how you actually get to this value of 'n' but the way you've asked the question you could go for a function style macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro create_list(basename,n);
  %local _var;
  %if &amp;amp;n&amp;gt;0 %then %let _var=&amp;amp;basename.1;
  %do i=2 %to &amp;amp;n;
    %let _var=&amp;amp;_var,&amp;amp;basename&amp;amp;i;
  %end;
  &amp;amp;_var
%mend;

%let variable=%create_list(x,6);

%put &amp;amp;=variable;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Dec 2016 02:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320086#M70437</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-12-20T02:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix variable name and assign it to macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320088#M70438</link>
      <description>impressive</description>
      <pubDate>Tue, 20 Dec 2016 02:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320088#M70438</guid>
      <dc:creator>Forecaster</dc:creator>
      <dc:date>2016-12-20T02:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix variable name and assign it to macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320154#M70463</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;pass it to a function" - in what sense do you need a macro or macro variable for this task. &amp;nbsp;Base SAS - the programming language - provides numerous different avenues to achieve these results without resorting to %$%% code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Arrays:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array x{6};&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;List of paramters:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;sum(of x:);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;List between paratmers:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;keep=x1--x6;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Etc.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2016 09:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320154#M70463</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-20T09:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix variable name and assign it to macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320208#M70486</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;I'm trying to pass the macro into a FMCP function which would be later used in an optimization procedure. For example: The key here is the when defining function fdef, lets suppose I have x1,x2,x3,x4,x5,x6. none of them work except hard coding. If there is a better way to pass the &amp;amp;var please let me know&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc fcmp outlib=sasuser.myfuncs.mypkg;

   function fdef(&amp;amp;var);
   array x[&amp;amp;n.];
   array y[&amp;amp;n.,&amp;amp;n.] /nosym (&amp;amp;mat.); 

	fx = 0;
 	do j = 1 to dim(y);
		fx = fx + (y[i,j]- (x[i]*x[j]));
      	
	end;
	return(fx);
   endsub;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2016 13:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320208#M70486</guid>
      <dc:creator>Forecaster</dc:creator>
      <dc:date>2016-12-20T13:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix variable name and assign it to macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320212#M70487</link>
      <description>&lt;P&gt;Seems to me like your trying to use every technology other than Base SAS. &amp;nbsp;Your given fuction can be copied into a datastep, no need to hide code behind a compiled function. &amp;nbsp;Your macro variables can be replaced with variable lists and arrays or ideally remodelling your data into a better normalised structure so that by groups can be utilised. &amp;nbsp;Also, as it looks like your are doing lots of calculations across arrays, perhaps proc iml may be the way to go.&lt;/P&gt;
&lt;P&gt;Anyways just opinion of course.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2016 13:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-variable-name-and-assign-it-to/m-p/320212#M70487</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-20T13:37:19Z</dc:date>
    </item>
  </channel>
</rss>

