<?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 an array with dimensions from another existing array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-an-array-with-dimensions-from-another-existing-array/m-p/737803#M230045</link>
    <description>&lt;P&gt;To define new variables you need to know how many to create &lt;STRONG&gt;BEFORE&lt;/STRONG&gt; that data step even starts running so there is no way the syntax you proposed could work (even if SAS modified the language to allow it).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might try this method to create a macro variable first and then use that in the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if 0 set have ;
  array cats category: ;
  call symputx('nvars',dim(cats));
  stop;
run;
data want;
  set have ;
  array cats category: ;
  array price [&amp;amp;nvars] ;
  ...
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Apr 2021 03:54:14 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-29T03:54:14Z</dc:date>
    <item>
      <title>Create an array with dimensions from another existing array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-array-with-dimensions-from-another-existing-array/m-p/737802#M230044</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset with&lt;STRONG&gt; existing&lt;/STRONG&gt; variables category_1-category_n. I want to create another array 'price' being price_1-price_n. Depending on the which version of the data I'm using the value of 'n' can change.&lt;/P&gt;&lt;P&gt;I tried this:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;array cats $ category: ;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;array price {dim(cats)} price:&lt;/EM&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which did not work. Would there be a way to achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 03:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-array-with-dimensions-from-another-existing-array/m-p/737802#M230044</guid>
      <dc:creator>rdum96</dc:creator>
      <dc:date>2021-04-29T03:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create an array with dimensions from another existing array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-array-with-dimensions-from-another-existing-array/m-p/737803#M230045</link>
      <description>&lt;P&gt;To define new variables you need to know how many to create &lt;STRONG&gt;BEFORE&lt;/STRONG&gt; that data step even starts running so there is no way the syntax you proposed could work (even if SAS modified the language to allow it).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might try this method to create a macro variable first and then use that in the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if 0 set have ;
  array cats category: ;
  call symputx('nvars',dim(cats));
  stop;
run;
data want;
  set have ;
  array cats category: ;
  array price [&amp;amp;nvars] ;
  ...
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 03:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-array-with-dimensions-from-another-existing-array/m-p/737803#M230045</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-29T03:54:14Z</dc:date>
    </item>
  </channel>
</rss>

