<?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: Can someone help me with the below array, which I am using the transpose 2 columns at the same t in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905337#M357590</link>
    <description>&lt;P&gt;Sorry should have specified this...... it needs to be dynamic because the number of columns could vary (its not always 5)&lt;/P&gt;</description>
    <pubDate>Thu, 30 Nov 2023 11:57:04 GMT</pubDate>
    <dc:creator>sasheadache</dc:creator>
    <dc:date>2023-11-30T11:57:04Z</dc:date>
    <item>
      <title>Can someone help me with the below array, which I am using the transpose 2 columns at the same time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905335#M357588</link>
      <description>&lt;P&gt;I am using code similar to the below - this works, however it creates all values from Nmbr_ first and then does the same for Bal_. I want the columns to be created in the order of Nmbr_1/Bal_1/Nmbr_2/Bal_2 etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The number of columns needs to be dynamic - so whilst I have put [5] in the sample code this number can change therefore I cannot use the retain function. (In my code I pass this from a macro token.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;  data want;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;    array Nmbr_[5] $14.;&amp;nbsp;&lt;BR /&gt;    array Bal_[5] ;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;    do _n_ = 1 by 1 until(last.var2);&amp;nbsp;&lt;BR /&gt;      set input;&amp;nbsp;&lt;BR /&gt;      by var1 var2;&amp;nbsp;&lt;BR /&gt;      Nmbr_[_n_] = Nmbr;&amp;nbsp;&lt;BR /&gt;      Bal_[_n_] = Bal;&amp;nbsp;&lt;BR /&gt;    end;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;    drop Nmbr Bal;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;  run;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 12:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905335#M357588</guid>
      <dc:creator>sasheadache</dc:creator>
      <dc:date>2023-11-30T12:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone help me with the below array, which I am using the transpose 2 columns at the same t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905336#M357589</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;I want the columns to be created in the order of Nmbr_1/Bal_1/Nmbr_2/Bal_2 etc.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try adding this statement as the first line in the DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain Nmbr_1 Bal_1 Nmbr_2 Bal_2 Nmbr_3 Bal_3 Nmbr_4 Bal_4 Nmbr_5 Bal_5;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Nov 2023 11:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905336#M357589</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-11-30T11:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone help me with the below array, which I am using the transpose 2 columns at the same t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905337#M357590</link>
      <description>&lt;P&gt;Sorry should have specified this...... it needs to be dynamic because the number of columns could vary (its not always 5)&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 11:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905337#M357590</guid>
      <dc:creator>sasheadache</dc:creator>
      <dc:date>2023-11-30T11:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone help me with the below array, which I am using the transpose 2 columns at the same t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905345#M357594</link>
      <description>&lt;P&gt;OK, then build the RETAIN statement with the variable names and then put it into a macro variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let numVars = 5;
data _null_;
length s $1000;
s = "retain ";
do i = 1 to &amp;amp;numVars;
   t = catt("Nmbr_", i, " Bal_", i);
   s = catx(' ', s, t);
end;
call symput("RetainStmt", s);
run;

%put &amp;amp;=RetainStmt;

data want;
    &amp;amp;RetainStmt;
    array Nmbr_[&amp;amp;numVars] $14.; 
    array Bal_[&amp;amp;numVars];
    /* ETC */
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Nov 2023 13:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905345#M357594</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-11-30T13:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone help me with the below array, which I am using the transpose 2 columns at the same t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905346#M357595</link>
      <description>Amazing thank you!!</description>
      <pubDate>Thu, 30 Nov 2023 13:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905346#M357595</guid>
      <dc:creator>sasheadache</dc:creator>
      <dc:date>2023-11-30T13:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone help me with the below array, which I am using the transpose 2 columns at the same t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905348#M357597</link>
      <description>&lt;P&gt;Alternatively use the retain statement directly with the array name. This will then retain all the array elements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array Nmbr_[&amp;amp;numVars] $14.; 
  array Bal_[&amp;amp;numVars];
  retain Nmbr_ Bal_;
  /* ETC */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Nov 2023 13:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905348#M357597</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-30T13:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone help me with the below array, which I am using the transpose 2 columns at the same t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905403#M357617</link>
      <description>&lt;P&gt;Do you know the number in advance?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or do you need to calculate it?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select max(count) into :n trimmed 
from (select var1,var2,count(*) as count from have group by var1,var2)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have the count you can generate the variable definitions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use macro code, but you would need to use a macro definition to allow the use of the %DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length 
%do i=1 %to &amp;amp;n ;
  Nmbr_&amp;amp;i $14 Bal_&amp;amp;i 8 
%end;
;
  array Nmbr_[5] ;
  array Bal_[5] ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could generate the LENGTH statement with a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code column=cc;
  put 'length ' @;
  do i=1 to &amp;amp;n;
    put 'Nmbr_' i '$14 Bal_' i '8 ' @;
    if cc&amp;gt;65 then put / '  ' @ ;
  end;
  put ';' ;
run;
data want;
%include code / source2;
  array Nmbr_[&amp;amp;n];
  array Bal_[&amp;amp;n];
....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 18:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-help-me-with-the-below-array-which-I-am-using-the/m-p/905403#M357617</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-30T18:30:10Z</dc:date>
    </item>
  </channel>
</rss>

