<?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 Array size based on another Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-size-based-on-another-Array/m-p/908117#M358408</link>
    <description>&lt;P&gt;I'm learning SAS Arrays. I have the following code:&lt;/P&gt;
&lt;PRE&gt;data work.DublinPrecipRotate;
    set pg3.weather_dublinmadrid_monthly5yr
       (keep=City Year PrecipQ1-PrecipQ4);
    where City='Dublin';
	array PrecipQ[*] PrecipQ:;
	Boundry=dim(PrecipQ);
	array Quarter[Boundry];
	do Q=1 to Boundry;
		Quarter[q] = PrecipQ[q] * 2.54;
	end;
run;&lt;/PRE&gt;
&lt;P&gt;SAS generates error mesg at:&lt;/P&gt;
&lt;PRE&gt;array Quarter[Boundry];&lt;/PRE&gt;
&lt;P&gt;If I explicitly put the array size:&lt;/P&gt;
&lt;PRE&gt;array Quarter[4];&lt;/PRE&gt;
&lt;P&gt;Then it works. How can I dynamically size Quarter array based on&amp;nbsp;PrecipQ array? Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 14 Dec 2023 22:01:26 GMT</pubDate>
    <dc:creator>current_thing</dc:creator>
    <dc:date>2023-12-14T22:01:26Z</dc:date>
    <item>
      <title>Array size based on another Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-size-based-on-another-Array/m-p/908117#M358408</link>
      <description>&lt;P&gt;I'm learning SAS Arrays. I have the following code:&lt;/P&gt;
&lt;PRE&gt;data work.DublinPrecipRotate;
    set pg3.weather_dublinmadrid_monthly5yr
       (keep=City Year PrecipQ1-PrecipQ4);
    where City='Dublin';
	array PrecipQ[*] PrecipQ:;
	Boundry=dim(PrecipQ);
	array Quarter[Boundry];
	do Q=1 to Boundry;
		Quarter[q] = PrecipQ[q] * 2.54;
	end;
run;&lt;/PRE&gt;
&lt;P&gt;SAS generates error mesg at:&lt;/P&gt;
&lt;PRE&gt;array Quarter[Boundry];&lt;/PRE&gt;
&lt;P&gt;If I explicitly put the array size:&lt;/P&gt;
&lt;PRE&gt;array Quarter[4];&lt;/PRE&gt;
&lt;P&gt;Then it works. How can I dynamically size Quarter array based on&amp;nbsp;PrecipQ array? Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 22:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-size-based-on-another-Array/m-p/908117#M358408</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2023-12-14T22:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Array size based on another Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-size-based-on-another-Array/m-p/908122#M358411</link>
      <description>&lt;P&gt;You don't.&amp;nbsp; It you put a variable name where the size should be SAS thinks you are trying to define the variable to use for implicit indexing into the array, like the way ARRAY statement worked before they introduced explicit indexing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it that you are trying to do?&lt;/P&gt;
&lt;P&gt;Why do you have multiple&amp;nbsp;PrecipQ... variables to begin with?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have multiple observations instead then your code is simple.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Quarter = PrecipQ * 2.54&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To do what you want you will need to first put the count into a macro variable and use the macro variable to generate the constant number that the ARRAY statement wants.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set pg3.weather_dublinmadrid_monthly5yr(obs=1 keep=PrecipQ:);
  array PrecipQ PrecipQ:;
  call symputx('N',dim(precipq));
run;

data work.DublinPrecipRotate;
  set pg3.weather_dublinmadrid_monthly5yr;
  where City='Dublin';
  array PrecipQ PrecipQ:;
  array Quarter[&amp;amp;n];
  keep City Year PrecipQ: Quarter1-Quarter&amp;amp;n;
  do Q=1 to &amp;amp;n;
    Quarter[q] = PrecipQ[q] * 2.54;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Dec 2023 22:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-size-based-on-another-Array/m-p/908122#M358411</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-14T22:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Array size based on another Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-size-based-on-another-Array/m-p/908126#M358413</link>
      <description>&lt;P&gt;Each data step has a compilation and an execution phase.&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/p08a4x7h9mkwqvn16jg3xqwfxful.htm" target="_self"&gt;Overview of DATA Step Processing&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The array gets defined during the compilation phase, any value assignment to variables only happens during the execution phase.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Boundry gets only populated during the execution phase and though you can't use it for the array definition that's done in the compilation phase.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1702593539075.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91429i1A7B30EEAACB9A37/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1702593539075.png" alt="Patrick_0-1702593539075.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 22:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-size-based-on-another-Array/m-p/908126#M358413</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-14T22:40:43Z</dc:date>
    </item>
  </channel>
</rss>

