<?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: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317876#M69625</link>
    <description>the sql gives me an error at "order by name" thinking and warns "assuming symbol OR was misspelled as order"&lt;BR /&gt;&lt;BR /&gt;if all the group variables are listed in order in the declared array as a double-dimensional, will it even reference properly with the dimensions?</description>
    <pubDate>Fri, 09 Dec 2016 12:24:19 GMT</pubDate>
    <dc:creator>chrisengel</dc:creator>
    <dc:date>2016-12-09T12:24:19Z</dc:date>
    <item>
      <title>Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317845#M69611</link>
      <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple datasets with variables in the following format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;group1I1-group1IY&lt;/P&gt;&lt;P&gt;group2I1-group2IY&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;groupXI1-groupXIY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My program processes with these variables by declaring a&amp;nbsp;two-dimensional array:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array group {&amp;amp;x, &amp;amp;y} group1I1-group&amp;amp;x.I&amp;amp;y;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This declaration fails. It works fine when I do it manually -- i.e., group1I1-group1I&amp;amp;y group2I1-group2I&amp;amp;y &amp;nbsp; etc etc , but when I try to do it like above, i get the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Alphabetic prefixes for enumerated variables (group1I1-group23I118) are different.&lt;/P&gt;&lt;P&gt;ERROR: Too few variables defined for the dimension(s) specified for the array group&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro is going to be run for many different sets, where the &amp;amp;x and &amp;amp;y will be changing, and thus I need to be able to declare the array more dynamically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there some syntax in the array declaration I am getting wrong, or do I have to write some macro within the macro to concatenate the group&amp;amp;x.I series separately?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any assistance.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 10:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317845#M69611</guid>
      <dc:creator>chrisengel</dc:creator>
      <dc:date>2016-12-09T10:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317848#M69613</link>
      <description>&lt;P&gt;The reason is that:&lt;BR /&gt;&lt;SPAN&gt;group1I &amp;nbsp; &amp;nbsp;!= &amp;nbsp; &amp;nbsp;group23I&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Simple as that. &amp;nbsp;The text prefix has to be the same,the number are the end is the only part which can change. Now if your variables are all there and in order, you could use:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array group {&amp;amp;x, &amp;amp;y} group1I1--group&amp;amp;x.I&amp;amp;y;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Two dashes mean variables from that one to that as positional. &amp;nbsp;This is dangerous as they might not be in order.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;TBH, you would be better off re-modelling your data. &amp;nbsp;Put groups going down the dataset:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;From:&lt;BR /&gt;group1l1 group1l2...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;to:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Group:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1L1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1L2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You will find your programming easier. &amp;nbsp;For instance you could stack all your datasets together, then just process one dataset.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 10:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317848#M69613</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-09T10:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317849#M69614</link>
      <description>how does that fix the problem of being able to declare the arrays for the groups across x and y though?&lt;BR /&gt;&lt;BR /&gt;If i just rename all the groupxIy variables to xIy and try to declare the array dynamically again, isn't it then back to the same problem?</description>
      <pubDate>Fri, 09 Dec 2016 10:40:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317849#M69614</guid>
      <dc:creator>chrisengel</dc:creator>
      <dc:date>2016-12-09T10:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317852#M69616</link>
      <description>&lt;P&gt;How does "what" fix the problem? &amp;nbsp;In the first example, I use -- which means positional parameter1 to positional paramter X, with each variable between in the order they apper in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the second example I am talking about normalising the data from wide which you have, to long, i.e. all the groups god down the datastet, so another example:&lt;/P&gt;
&lt;P&gt;ABC1L1 &amp;nbsp;... &amp;nbsp;ABC13L1 &amp;nbsp;... ABC15L5...&lt;/P&gt;
&lt;P&gt;11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 56 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To:&lt;/P&gt;
&lt;P&gt;GROUP &amp;nbsp; &amp;nbsp; &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;ABC1L1 &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;ABC13L1 &amp;nbsp; &amp;nbsp; 56&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;ABC15L15 &amp;nbsp; &amp;nbsp;8&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then stack all your datasets into one, maybe have another variable called variable. &amp;nbsp; Then you can do your processing on this one dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 10:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317852#M69616</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-09T10:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317854#M69618</link>
      <description>&lt;P&gt;Oh, that won't work. The data needs to be wide and I need to be able to arrange the variables so I can declare them dynamically in array. Additionally, the double-dash doesnt work since they aren't in proper order and it causes an over-declaration of too many vars.&lt;BR /&gt;&lt;BR /&gt;I guess I can do some kind of loop like this instead:&lt;BR /&gt;&lt;BR /&gt;%let arrayvar=;&lt;BR /&gt;%do i=1 %to &amp;amp;x;&lt;BR /&gt;%do j=1 %to &amp;amp;y;&lt;BR /&gt;%let arrayvar=&amp;amp;arrayvar group1I.&amp;amp;y-group&amp;amp;i.I&amp;amp;y;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;array group{&amp;amp;x, &amp;amp;y} &amp;amp;arrayvar;&lt;BR /&gt;&lt;BR /&gt;I haven't tested this I'm just proposing it as an idea, since I know the declaration of the variables this way works, just dont know if dynamically it can be achieved like above?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 10:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317854#M69618</guid>
      <dc:creator>chrisengel</dc:creator>
      <dc:date>2016-12-09T10:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317856#M69619</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;The data needs to be wide" - why? &amp;nbsp;The way you program has nothing to do with any inputs or outputs from the program. &amp;nbsp;You are just making your life a lot harder by retaining that method of working.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And your example code given will not work either. &amp;nbsp;The variable names themselves are the problem. &amp;nbsp;To use syntax such as:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;variable&amp;lt;suffix&amp;gt;-variable&amp;lt;suffix&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The variable in the above needs to be the same, and as we have established:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;group1I &amp;nbsp; &amp;nbsp;!= &amp;nbsp; &amp;nbsp;group23I&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The only other way I can think of doing it would be to create a full list of variables from the metdata:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select distinct NAME
  into    :VLIST separated by " "
  from   (select  *
            from    DICTIONARY.COLUMNS
            where LIBNAME="WORK"
              and  MEMNAME="&amp;lt;yourdataset&amp;gt;"
              and substr(NAME,1,5)="GROUP"
            order by NAME);
quit;

data want;
  set &amp;lt;yourdataset&amp;gt;;
  array group{&amp;amp;x.,&amp;amp;y.} &amp;amp;vlist.;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;As you can see, the coding for this is geting more and more complicated, all due to poor data modelling choices.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 11:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317856#M69619</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-09T11:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317876#M69625</link>
      <description>the sql gives me an error at "order by name" thinking and warns "assuming symbol OR was misspelled as order"&lt;BR /&gt;&lt;BR /&gt;if all the group variables are listed in order in the declared array as a double-dimensional, will it even reference properly with the dimensions?</description>
      <pubDate>Fri, 09 Dec 2016 12:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317876#M69625</guid>
      <dc:creator>chrisengel</dc:creator>
      <dc:date>2016-12-09T12:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317879#M69626</link>
      <description>I think I have an idea.&lt;BR /&gt;&lt;BR /&gt;The double-dash method should work as long as I get the variables ordered properly, right?&lt;BR /&gt;&lt;BR /&gt;So if I reorder everything alphabetically in the dataset and just doubledash across group* then it ought to be "safe" to declare the array</description>
      <pubDate>Fri, 09 Dec 2016 12:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317879#M69626</guid>
      <dc:creator>chrisengel</dc:creator>
      <dc:date>2016-12-09T12:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317886#M69628</link>
      <description>I have a different question that I'll just make a new thread for since none of these solutions will work actually</description>
      <pubDate>Fri, 09 Dec 2016 13:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317886#M69628</guid>
      <dc:creator>chrisengel</dc:creator>
      <dc:date>2016-12-09T13:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically declare multi-dimensional array -- Alphabetic prefixes are different, too few variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317888#M69629</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And your example code given will not work either. &amp;nbsp;The variable names themselves are the problem. &lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I actually have the solution now, and a variation of the code I provided works just fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%let varlist=;&lt;BR /&gt;%let j=118;
%do i=1 %to 23;
%let arrayvar&amp;amp;i=group&amp;amp;i.I1-group&amp;amp;i.I&amp;amp;j;
%end;
%do i=1 %to 23;
%let varlist=&amp;amp;varlist &amp;amp;&amp;amp;arrayvar&amp;amp;i;
%end;
%put &amp;amp;varlist;
%mend;

%test;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The 23 and 118 i grab dynamically through datasets so I replace those with &amp;amp;x and &amp;amp;y in the code and works like a charm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The varlist variable contains a nice list in proper order of the relevant dimensions of variables to declare the array ina clean way:&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 group{&amp;amp;x, &amp;amp;y} &amp;amp;varlist;
...
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I provide this code in case others need to dynamically declare arrays using specific dimensions of existing variables in a dataset that don't conform to a nice alphabetical format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 13:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-declare-multi-dimensional-array-Alphabetic-prefixes/m-p/317888#M69629</guid>
      <dc:creator>chrisengel</dc:creator>
      <dc:date>2016-12-09T13:34:46Z</dc:date>
    </item>
  </channel>
</rss>

