<?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 macro in order to create an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448845#M112963</link>
    <description>&lt;P&gt;In a data step an "array" is just a convenient way to group variables. It is totally different from the real arrays and matrices that you work with in PROC IML.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you actually want to do. Show a small sample input dataset.&amp;nbsp; Then show what you want to do.&amp;nbsp; Show the resulting dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A macro is just a tool to generate code. So show the code that you want to generate and explain what parts of it you need vary.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 02:13:46 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-03-27T02:13:46Z</dc:date>
    <item>
      <title>create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448816#M112957</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a macro %array which will do the following think:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%array(y,0, n) will return for an array which length n&amp;nbsp;and beginning at time t=0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%array(x,1, n);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%array(y,0, n);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do t = &lt;STRONG&gt;1&lt;/STRONG&gt;&amp;nbsp;to n;&lt;/P&gt;&lt;P&gt;x_(t) = y_(t) *3+2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;y(&lt;STRONG&gt;0&lt;/STRONG&gt;) = R_0 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do t = &lt;STRONG&gt;1&lt;/STRONG&gt; to &amp;amp;H.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y(t) = x(t)+ y(t-&lt;STRONG&gt;1&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for you help&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 21:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448816#M112957</guid>
      <dc:creator>madix</dc:creator>
      <dc:date>2018-03-26T21:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448819#M112958</link>
      <description>&lt;P&gt;It's not clear to me what your question is.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 21:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448819#M112958</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-26T21:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448821#M112959</link>
      <description>&lt;P&gt;I just want a macro which create an array by giving&amp;nbsp;the name, the initial index number and the final one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example %array(z,0,n) will create an array which name is z and where I can go from z(0) to z(n).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it better?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 23:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448821#M112959</guid>
      <dc:creator>madix</dc:creator>
      <dc:date>2018-03-26T23:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448826#M112960</link>
      <description>&lt;P&gt;I suspect that someone with better IML skills could show you how to do that.&lt;/P&gt;
&lt;P&gt;But if you just want to build a matrix of literal values. Then looking at this documentation page.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=imlug&amp;amp;docsetTarget=imlug_workmatrix_sect004.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=imlug&amp;amp;docsetTarget=imlug_workmatrix_sect004.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You can see that you just need make a statement like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;y={0 1 2 3} ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So here is a macro that could do that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro array(name,start,end) ;
%local i  ;
&amp;amp;name = {
%do i=&amp;amp;start %to &amp;amp;end; &amp;amp;i %end;
};
%mend ; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If course you could also just use the simple syntax like in this help page.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=imlug&amp;amp;docsetTarget=imlug_workmatrix_sect014.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=imlug&amp;amp;docsetTarget=imlug_workmatrix_sect014.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 23:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448826#M112960</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-26T23:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448831#M112961</link>
      <description>&lt;P&gt;All arrays in the SAS/IML language are 1-based, which means that you can't use y[0].&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get started with the basics of SAS/IML, see &lt;A href="https://blogs.sas.com/content/iml/2014/08/11/ten-tips-for-learning-sasiml.html" target="_self"&gt;"Ten tips for learning the SAS/IML language."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your problem, I don't know what you are trying to accomplish, but here is some working code that you can play with to get started:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
n=10; 
R_0 = 2;
x = j(n,   1, 0);   /* allocate (n x 1) vector; init to 0 */
y = j(n+1, 1, 0);   /* allocate (n+1 x 1) vector; init to 0 */

y[1] = R_0;         /* set first element to R_0 */
do t = 1 to n;
  x[t] = y[t]*3 + 2;
  do k = 2 to n;
     y[k] = x[k] + y[k-1];
  end;
end;

print x y;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Mar 2018 00:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448831#M112961</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-03-27T00:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448834#M112962</link>
      <description>&lt;P&gt;Thank you for your reply. &amp;nbsp;I would like to do it without iml. I would like to create such a vector inside a data step. So if I use j(.,.,.) it won't work. Do you know how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 00:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448834#M112962</guid>
      <dc:creator>madix</dc:creator>
      <dc:date>2018-03-27T00:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448845#M112963</link>
      <description>&lt;P&gt;In a data step an "array" is just a convenient way to group variables. It is totally different from the real arrays and matrices that you work with in PROC IML.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you actually want to do. Show a small sample input dataset.&amp;nbsp; Then show what you want to do.&amp;nbsp; Show the resulting dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A macro is just a tool to generate code. So show the code that you want to generate and explain what parts of it you need vary.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 02:13:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448845#M112963</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-27T02:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448937#M112964</link>
      <description>&lt;P&gt;Since this is the SAS/IML Support Community, I assumed you wanted help with IML.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would you like me to move this thread to the Community for DATA step programming?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 11:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/448937#M112964</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-03-27T11:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro in order to create an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/449027#M112965</link>
      <description>&lt;P&gt;Does the index really matter?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS array statement does that by default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array X(0:25) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;You get X1-X26 because you have 26. So in this case, using an array will not save you anything unless you're trying to initialize the&amp;nbsp; data. Since SAS uses an index of 1 compared to other languages, changing your index to 1 will simplify your life greatly as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%array(z, 0, 25);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, there's very little difference here so there's no value to a macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being said, the following should be all you need, but again, it adds unnecessary complexity to your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro setUpArray(z, start, end);

array &amp;amp;z.(&amp;amp;start.:&amp;amp;end.) &amp;amp;z.&amp;amp;start.-&amp;amp;z&amp;amp;end.;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 15:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-in-order-to-create-an-array/m-p/449027#M112965</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-27T15:44:07Z</dc:date>
    </item>
  </channel>
</rss>

