<?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: Specify a differing range of columns in an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569545#M160514</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278522"&gt;@bignate1030&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a table that looks like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Col1&amp;nbsp; &amp;nbsp; Col2&amp;nbsp; &amp;nbsp; Col3&amp;nbsp; &amp;nbsp; Col4&amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;-----------------------------------------&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to calculate some mins and maxes of the columns in my table, however the number of columns will change every time and I need to start at the third column, the name of which also changes. I know there exists the code for static arrays but is there some way I can modify that for my needs like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY X{ncol(my_table)-2} Col3-Last;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not anything dynamic but if the variables already exist in your data and the columns are adjacent as you imply you can use the -- (that is 2 dashes) list operator to define the array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array x col3varname -- lastvarname.&lt;/P&gt;
&lt;P&gt;You do not need to specify the size of the array if you use existing variables .&lt;/P&gt;
&lt;PRE&gt;data example;
   set sashelp.class;
   array m age -- weight;
   x= max(of m(*));
   y= min(of m(*));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jun 2019 17:31:31 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-06-27T17:31:31Z</dc:date>
    <item>
      <title>Specify a differing range of columns in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569542#M160511</link>
      <description>&lt;P&gt;I have a table that looks like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Col1&amp;nbsp; &amp;nbsp; Col2&amp;nbsp; &amp;nbsp; Col3&amp;nbsp; &amp;nbsp; Col4&amp;nbsp; &amp;nbsp; ...&lt;/P&gt;&lt;P&gt;-----------------------------------------&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to calculate some mins and maxes of the columns in my table, however the number of columns will change every time and I need to start at the third column, the name of which also changes. I know there exists the code for static arrays but is there some way I can modify that for my needs like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY X{ncol(my_table)-2} Col3-Last;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 17:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569542#M160511</guid>
      <dc:creator>bignate1030</dc:creator>
      <dc:date>2019-06-27T17:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Specify a differing range of columns in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569543#M160512</link>
      <description>&lt;P&gt;Here is one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   array x {10};
   do i=1 to 100;
      do j=1 to dim(x);
         x[j]=rand('integer', 1, 10);
      end;
      output;
   end;
run;

proc sql noprint;
   select name into :vars separated by ' ' 
   from dictionary.columns
   where libname='WORK' &amp;amp; memname='HAVE' &amp;amp; varnum ge 3;
quit;

%put &amp;amp;vars.;

data want;
   set have;
   array MyArray{*} &amp;amp;vars.;
   /* More Code */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 17:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569543#M160512</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-27T17:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Specify a differing range of columns in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569545#M160514</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278522"&gt;@bignate1030&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a table that looks like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Col1&amp;nbsp; &amp;nbsp; Col2&amp;nbsp; &amp;nbsp; Col3&amp;nbsp; &amp;nbsp; Col4&amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;-----------------------------------------&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to calculate some mins and maxes of the columns in my table, however the number of columns will change every time and I need to start at the third column, the name of which also changes. I know there exists the code for static arrays but is there some way I can modify that for my needs like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY X{ncol(my_table)-2} Col3-Last;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not anything dynamic but if the variables already exist in your data and the columns are adjacent as you imply you can use the -- (that is 2 dashes) list operator to define the array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array x col3varname -- lastvarname.&lt;/P&gt;
&lt;P&gt;You do not need to specify the size of the array if you use existing variables .&lt;/P&gt;
&lt;PRE&gt;data example;
   set sashelp.class;
   array m age -- weight;
   x= max(of m(*));
   y= min(of m(*));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 17:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569545#M160514</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-27T17:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Specify a differing range of columns in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569554#M160520</link>
      <description>&lt;P&gt;The variables already exist but I don't know how many there are. I am analyzing variables at different time frames, so I have a table that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Person&amp;nbsp; &amp;nbsp; Event&amp;nbsp; &amp;nbsp; Var_X_100_Days&amp;nbsp; &amp;nbsp; Var_X_6_Months.&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I can calculate min, max for that variable. However once I've done that I need to do the same for Var_Y. But the table for Var_Y looks like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Person&amp;nbsp; &amp;nbsp; Event&amp;nbsp; &amp;nbsp; Var_Y_6_Months&amp;nbsp; &amp;nbsp; Var_Y_1_Year&amp;nbsp; &amp;nbsp; Var_Y_2_Years&amp;nbsp; &amp;nbsp; Var_Y_3_Years&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I can't define a static range such as Var_X_100_Days -- Var_X_6_Months because the first and last variables will almost always have different names depending on what variable I am analyzing. However I know that the first variable will always be the third column and the last variable will always be the last column.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 17:46:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569554#M160520</guid>
      <dc:creator>bignate1030</dc:creator>
      <dc:date>2019-06-27T17:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Specify a differing range of columns in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569557#M160522</link>
      <description>You have a data structure problem. It will be much easier to help if you can show what you're starting with and what you want to end up with. With some actual data. There are often short cut ways to refer to variables that can help. &lt;BR /&gt;&lt;BR /&gt;If you always know the variable are from 3 to end though it can be very easy if that's the only logic you need to incorporate. Just pull that information from the sashelp.vtable using varnum, getting number 3 and the largest value and then creating macro variables. &lt;BR /&gt;&lt;BR /&gt;then declare your array as&lt;BR /&gt;&lt;BR /&gt;array myArray(*) thirdVar -- lastVar;&lt;BR /&gt;And you're fine. &lt;BR /&gt;&lt;BR /&gt;If all start with the same prefix, as in your example above you can also simplify that by not using the sashelp table at all.&lt;BR /&gt;&lt;BR /&gt;array myArray(*) var_: ;&lt;BR /&gt;&lt;BR /&gt;The colon tells SAS to take all variables that start with Var_.</description>
      <pubDate>Thu, 27 Jun 2019 17:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569557#M160522</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-27T17:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Specify a differing range of columns in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569558#M160523</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278522"&gt;@bignate1030&lt;/a&gt;&amp;nbsp;have you tried my code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if the variables of interest have a common prefix, you can simply do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array MyArray{*} Var:;
   /* More Code */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 17:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569558#M160523</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-27T17:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Specify a differing range of columns in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569560#M160525</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278522"&gt;@bignate1030&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The variables already exist but I don't know how many there are. I am analyzing variables at different time frames, so I have a table that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Person&amp;nbsp; &amp;nbsp; Event&amp;nbsp; &amp;nbsp; Var_X_100_Days&amp;nbsp; &amp;nbsp; Var_X_6_Months.&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I can calculate min, max for that variable. However once I've done that I need to do the same for Var_Y. But the table for Var_Y looks like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Person&amp;nbsp; &amp;nbsp; Event&amp;nbsp; &amp;nbsp; Var_Y_6_Months&amp;nbsp; &amp;nbsp; Var_Y_1_Year&amp;nbsp; &amp;nbsp; Var_Y_2_Years&amp;nbsp; &amp;nbsp; Var_Y_3_Years&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I can't define a static range such as Var_X_100_Days -- Var_X_6_Months because the first and last variables will almost always have different names depending on what variable I am analyzing. However I know that the first variable will always be the third column and the last variable will always be the last column.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If Person and Event are character variables then you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array m _numeric_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise you're going to have to use something like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;shows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or possibly reconsider how your data is structured or generating names like Var_Y_6_Months&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 17:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Specify-a-differing-range-of-columns-in-an-array/m-p/569560#M160525</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-27T17:54:20Z</dc:date>
    </item>
  </channel>
</rss>

