<?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 SAS array with variable dimension in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816504#M322304</link>
    <description>&lt;P&gt;the code just run forever, I cannot see any errors or the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the values of the two macro variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;33 %put &amp;amp;nombre_obs_IA.;&lt;BR /&gt;13415&lt;BR /&gt;34 %put &amp;amp;nb_scn. ;&lt;BR /&gt;1000&lt;/P&gt;</description>
    <pubDate>Sat, 04 Jun 2022 17:05:11 GMT</pubDate>
    <dc:creator>afsand</dc:creator>
    <dc:date>2022-06-04T17:05:11Z</dc:date>
    <item>
      <title>Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816501#M322301</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a dynamic array with variable dimensions, but the code is not working.&lt;/P&gt;&lt;P&gt;Can you please help with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data _null_ ;&lt;/P&gt;&lt;P&gt;set adherants ;&lt;/P&gt;&lt;P&gt;if _n_=1 then do;&lt;BR /&gt;array p_reserve_adh_path_ac_FR[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.];&lt;BR /&gt;array p_reserve_adh_path_ss_FR[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.];&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 16:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816501#M322301</guid>
      <dc:creator>afsand</dc:creator>
      <dc:date>2022-06-04T16:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816502#M322302</link>
      <description>&lt;P&gt;Not working? That's not enough information. Explain further, please. If there are errors in the log, show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for this data step (do not select parts to show us an not show us other parts).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Also, please provide the values of your macro variables.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 16:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816502#M322302</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-04T16:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816503#M322303</link>
      <description>&lt;P&gt;Show us where the values are set for the macro variables &amp;amp;nombre_obs_IA. are set &amp;amp;nb_scn AND what the actual values are.&lt;/P&gt;
&lt;P&gt;Also, instead of using a DATA _NULL_ try using some actual data set so that you can see if the variables were created. _NULL_ does not create any data set so the variables only would exist while that data step is running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ARRAY statements are declarative not executable.&amp;nbsp; The use of the "if _n_= 1" has no effect on the behavior of the array statements and as shown in that example is a completely useless condition.&lt;/P&gt;
&lt;P&gt;EVERY record in a SAS data set &lt;STRONG&gt;will have&lt;/STRONG&gt; the exact same number of variables. Period. There is no way to have a variable exist on only one row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run this code you will see that there are 3 new variables added to set in the new data set JUNK and since there is no attempt to assign values they are all missing.&lt;/P&gt;
&lt;PRE&gt;%let somedim=3;

data junk;
   set sashelp.class;
   array new (&amp;amp;somedim.);
run;
&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413930"&gt;@afsand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a dynamic array with variable dimensions, but the code is not working.&lt;/P&gt;
&lt;P&gt;Can you please help with this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data _null_ ;&lt;/P&gt;
&lt;P&gt;set adherants ;&lt;/P&gt;
&lt;P&gt;if _n_=1 then do;&lt;BR /&gt;array p_reserve_adh_path_ac_FR[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.];&lt;BR /&gt;array p_reserve_adh_path_ss_FR[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.];&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 17:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816503#M322303</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-04T17:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816504#M322304</link>
      <description>&lt;P&gt;the code just run forever, I cannot see any errors or the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the values of the two macro variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;33 %put &amp;amp;nombre_obs_IA.;&lt;BR /&gt;13415&lt;BR /&gt;34 %put &amp;amp;nb_scn. ;&lt;BR /&gt;1000&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 17:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816504#M322304</guid>
      <dc:creator>afsand</dc:creator>
      <dc:date>2022-06-04T17:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816507#M322307</link>
      <description>&lt;P&gt;SHOW US the log. All of it. Even if there are no obvious errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 17:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816507#M322307</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-04T17:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816508#M322308</link>
      <description>&lt;P&gt;Thank you for your reply, I understand more. I think an array is not what I need for what I am trying to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am doing some calculations on a data step table and I also want to create an output table containing the results. I tried to create an array like below and output the results of the array but it seems not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you suggest me to create a data step table for the outputs instead of an array? if yes, how to output the results only in the ouput data table? I have never worked on two SAS tables at the same time, how to ouput only on a table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data _null_ ;&lt;/P&gt;&lt;P&gt;set adherants ;&lt;/P&gt;&lt;P&gt;array p_reserve_adh_path_ac_FR[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.];&lt;BR /&gt;array p_reserve_adh_path_ss_FR[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----some calculations in between&lt;/P&gt;&lt;P&gt;----some calculations in between&lt;/P&gt;&lt;P&gt;---some calculations in between&lt;/P&gt;&lt;P&gt;---some calculations in between&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;p_reserve_adh_path_ac_FR[x,y] = sum(p_reserve_adh_path_ac_FR[x,y],0) + (A_ECH + A_DECES + A_RETRA + A_gross_up - A_FRAIS_GAR + (A_FRAIS_ADM - A_MERDISPO)) * fct_tx_fwrd;&lt;/P&gt;&lt;P&gt;p_reserve_adh_path_ss_FR[x,y] = sum(p_reserve_adh_path_ss_FR[x,y],0) + (A_ECH + A_gross_up + A_DECES + A_RETRA - A_FRAIS_GAR) * fct_tx_fwrd;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 17:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816508#M322308</guid>
      <dc:creator>afsand</dc:creator>
      <dc:date>2022-06-04T17:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816509#M322309</link>
      <description>&lt;P&gt;So you want to create two arrays, each with 13,415,000 cells.&amp;nbsp; I just tried it with the program below, which didn't do any actual data processing.&amp;nbsp; Instead it took 60 seconds, and exited with a&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;FATAL: Insufficient memory to execute DATA step program. Aborted during the COMPILATION phase.&lt;BR /&gt;ERROR: The SAS System stopped processing this step because of insufficient memory.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;message.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nombre_obs_IA=13415;
%let nb_scn=1000;


data _null_;
  array a[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.] ;
  array b[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.] ;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But SAS makes no objections when the arrays are defined as _temporary_:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    array a[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.] _temporary_;
    array b[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.] _temporary_;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, for _temporary_ arrays, you have to be aware that values are retained across iterations of the DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suppose, if your problem is a memory constraint, that you might be able to allocate more ram to the sas process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the real question is:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;why do you need two matrices with 13,415,000 cells each?&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 18:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816509#M322309</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-06-04T18:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816510#M322310</link>
      <description>Thank you very much, it works with the temporary option. I am running 700,000 scenarios for my work and I need to save the results of my calculations in a new output table. it seems easier in my head to use an array, but I understand that it is not that efficient. You can I output some calculated new variables in a new SAS table? you can see my code below.&lt;BR /&gt;&lt;BR /&gt;I want to create a table called output, that will be populated with calculated new variables.&lt;BR /&gt;&lt;BR /&gt;Data _null_ ;&lt;BR /&gt;&lt;BR /&gt;set adherants ;&lt;BR /&gt;&lt;BR /&gt;array p_reserve_adh_path_ac_FR[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.];&lt;BR /&gt;array p_reserve_adh_path_ss_FR[&amp;amp;nombre_obs_IA.,&amp;amp;nb_scn.];&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;----some calculations in between&lt;BR /&gt;&lt;BR /&gt;----some calculations in between&lt;BR /&gt;&lt;BR /&gt;---some calculations in between&lt;BR /&gt;&lt;BR /&gt;---some calculations in between&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;p_reserve_adh_path_ac_FR[x,y] = sum(p_reserve_adh_path_ac_FR[x,y],0) + (A_ECH + A_DECES + A_RETRA + A_gross_up - A_FRAIS_GAR + (A_FRAIS_ADM - A_MERDISPO)) * fct_tx_fwrd;&lt;BR /&gt;&lt;BR /&gt;p_reserve_adh_path_ss_FR[x,y] = sum(p_reserve_adh_path_ss_FR[x,y],0) + (A_ECH + A_gross_up + A_DECES + A_RETRA - A_FRAIS_GAR) * fct_tx_fwrd;&lt;BR /&gt;&lt;BR /&gt;run;</description>
      <pubDate>Sat, 04 Jun 2022 19:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816510#M322310</guid>
      <dc:creator>afsand</dc:creator>
      <dc:date>2022-06-04T19:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816511#M322311</link>
      <description>&lt;P&gt;But the problem with a temporary array is that its values are not part of the program data vector, and therefore will not be output to a dataset, unless you copy those values to a regular variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 20:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816511#M322311</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-06-04T20:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816514#M322313</link>
      <description>&lt;P&gt;A data _NULL_ step is not going to create any data.&amp;nbsp; If you want to make a dataset then give it a name (or don't use a name at all and SAS will generate one in the series DATA1, DATA2, ....)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But do NOT try to create a dataset with millions of variables.&amp;nbsp; Millions of observations is reasonable, but they should each have a reasonable number of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An ARRAY in SAS is just a method for choosing which variable to access based on an index into a list of variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you could think of a SAS dataset as a two dimensional array.&amp;nbsp; The variables are the columns and the observations are the rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could store an N-dimensional matrix in a dataset by using N+1 variables. One for each of the indexes and the extra one for the actual value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain what is the INPUT for this problem?&amp;nbsp; What is the OUTPUT that you want?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 21:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816514#M322313</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-04T21:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816521#M322317</link>
      <description>&lt;P&gt;Where do x and y come from? Are they part of dataset adherants, or are they calculated in the data step?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2022 05:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816521#M322317</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-05T05:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS array with variable dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816522#M322318</link>
      <description>&lt;P&gt;Can you describe the logic of your program. Maybe it can be done without arrays.&lt;/P&gt;
&lt;P&gt;What are the initial values in an array - are they values assigned from your input data?&lt;/P&gt;
&lt;P&gt;Next code illustarates creating an output data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep = &amp;lt;reqired list of variables&amp;gt;);
  set have;&lt;BR /&gt;        ...
       if &amp;lt;condition&amp;gt; then output want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;May be it is possible to do the work in several steps, using some temporary tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp1;
  set have;
       .... first step code ...
      keep &amp;lt;ID and calculated variables on output&amp;gt;;
run;

data want;
 set temp1;
       ... final calaulations ...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2022 05:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-SAS-array-with-variable-dimension/m-p/816522#M322318</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2022-06-05T05:34:38Z</dc:date>
    </item>
  </channel>
</rss>

