<?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: array length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/761318#M240890</link>
    <description>Thanks for the lengthy reply. Personally, I am not confusing anything. My &amp;amp;maxlength. was 6 which resulted in 6 new variables in my case. I was having an issue with the default length of the 6 variables, which was truncating the strings I assigned to them. The way I read OP's question, it seemed he wanted to store different lengths in his array variables so I provided my solution. If OP was referring to something else, he's have to jump to some other answer.</description>
    <pubDate>Thu, 12 Aug 2021 23:51:49 GMT</pubDate>
    <dc:creator>Elle</dc:creator>
    <dc:date>2021-08-12T23:51:49Z</dc:date>
    <item>
      <title>array length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/61074#M13257</link>
      <description>Is it possible to create a array with length after calculations in data steps or in macro?&lt;BR /&gt;
for example, i calculate the length of array required is array_length:&lt;BR /&gt;
data;&lt;BR /&gt;
a='asdfgh';&lt;BR /&gt;
b='axmnbkl';&lt;BR /&gt;
n=length(a);&lt;BR /&gt;
m=length(b);&lt;BR /&gt;
array_length=2*(n+m)+1;&lt;BR /&gt;
array V(array_length);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
of course the above example will return errors, but it illustrate what i want to do.</description>
      <pubDate>Fri, 06 Aug 2010 08:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/61074#M13257</guid>
      <dc:creator>justforgetit</dc:creator>
      <dc:date>2010-08-06T08:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: array length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/61075#M13258</link>
      <description>The parameter you are attempting to set (subscript -- within the parentheses) has no bearing on the SAS variable value length at all.  Re-visit the DOC.&lt;BR /&gt;
&lt;BR /&gt;
Suggest you start over and explain what it is you want to accomplish with the SAS system and why.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search arguments, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
array statement site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
array introduction site:sas.com</description>
      <pubDate>Fri, 06 Aug 2010 12:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/61075#M13258</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-06T12:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: array length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/61076#M13259</link>
      <description>hi justforgetit&lt;BR /&gt;
the simple answer for you is NO&lt;BR /&gt;
 &lt;BR /&gt;
SAS data step arrays have a length that must be declared at compile-time and the kind of variables you demonstrate using, have no value at compile time. &lt;BR /&gt;
 &lt;BR /&gt;
 Data step hash tables (also called associative arrays) define their memory  at "run-time" and so these could be defined as you seem to seek. However hash tables are defined differently from your example.&lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
peterC</description>
      <pubDate>Fri, 06 Aug 2010 13:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/61076#M13259</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-06T13:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: array length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/61077#M13260</link>
      <description>Hi:&lt;BR /&gt;
  &lt;BR /&gt;
This paper is a good introduction to Array processing:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/forum2007/273-2007.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/forum2007/273-2007.pdf&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Normally, you do not need to worry about the length of an array, because in SAS, an array is not a physical data construct (as it is in some languages). An array in SAS is a convenient way to reference a group of separate variables as though they were stored in an array. &lt;BR /&gt;
&lt;BR /&gt;
The variables, when they are stored internally in a SAS dataset are stored by their individual names. For the duration of a DATA step program, however, you can treat a group of variables as though they were members of an array for ease of processing and reference. So these are all valid DATA step array references:&lt;BR /&gt;
[pre]&lt;BR /&gt;
array lovelucy $ fred ethel lucy ricky;&lt;BR /&gt;
array regsl regsale1 regsale2 regsale3 regsale4;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                &lt;BR /&gt;
In the first array, LOVELUCY, the character variables FRED, ETHEL, LUCY and RICKY are being treated as array members LOVELUCY(1), LOVELUCY(2), LOVELUCY(3) and LOVELUCY(4) respectively. While in the second ARRAY statement, the REGSL array will be composed of the individual variables REGSALE1, REGSALE2, REGSALE3 and REGSALE4 and can be treated as array members using the array syntax: REGSL(1), REGSL(2), REGSL(3) and REGSL(4).&lt;BR /&gt;
 &lt;BR /&gt;
I could also declare an array to be composed of all my character variables or all my numeric variables (which I might want to do if I was testing for the presence or absence of missing values):&lt;BR /&gt;
[pre]&lt;BR /&gt;
array cv $ _character_;&lt;BR /&gt;
array nv _numeric_;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                            &lt;BR /&gt;
In a DATA step program you could use a DATA step DO loop to iterate through an array in order to perform some kind of processing. For the first 2 ARRAY statements, the number of variables in the array is known, but in the second set of ARRAY statements, the number of variables is unknown. However, the DIM function would allow me to operate a DO loop in the DATA step from 1 to the DIM(...) of the array.&lt;BR /&gt;
 &lt;BR /&gt;
Consider this program below, which treats all the numeric variables in SASHELP.CLASS like array members (program and log output shown here).&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
529&lt;BR /&gt;
530  data testit;&lt;BR /&gt;
531    set sashelp.class(obs=5);&lt;BR /&gt;
532    array myv _numeric_;&lt;BR /&gt;
533    do i = 1 to dim(myv);&lt;BR /&gt;
534      thisvar = vname(myv(i));&lt;BR /&gt;
535      put _n_= Name= i= thisvar= ' value is: ' myv(i);&lt;BR /&gt;
536    end;&lt;BR /&gt;
537  run;&lt;BR /&gt;
                                      &lt;BR /&gt;
_N_=1 Name=Alfred i=1 thisvar=Age  value is: 14&lt;BR /&gt;
_N_=1 Name=Alfred i=2 thisvar=Height  value is: 69&lt;BR /&gt;
_N_=1 Name=Alfred i=3 thisvar=Weight  value is: 112.5&lt;BR /&gt;
_N_=2 Name=Alice i=1 thisvar=Age  value is: 13&lt;BR /&gt;
_N_=2 Name=Alice i=2 thisvar=Height  value is: 56.5&lt;BR /&gt;
_N_=2 Name=Alice i=3 thisvar=Weight  value is: 84&lt;BR /&gt;
_N_=3 Name=Barbara i=1 thisvar=Age  value is: 13&lt;BR /&gt;
_N_=3 Name=Barbara i=2 thisvar=Height  value is: 65.3&lt;BR /&gt;
_N_=3 Name=Barbara i=3 thisvar=Weight  value is: 98&lt;BR /&gt;
_N_=4 Name=Carol i=1 thisvar=Age  value is: 14&lt;BR /&gt;
_N_=4 Name=Carol i=2 thisvar=Height  value is: 62.8&lt;BR /&gt;
_N_=4 Name=Carol i=3 thisvar=Weight  value is: 102.5&lt;BR /&gt;
_N_=5 Name=Henry i=1 thisvar=Age  value is: 14&lt;BR /&gt;
_N_=5 Name=Henry i=2 thisvar=Height  value is: 63.5&lt;BR /&gt;
_N_=5 Name=Henry i=3 thisvar=Weight  value is: 102.5&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 06 Aug 2010 23:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/61077#M13260</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-06T23:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: array length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/760987#M240721</link>
      <description>&lt;P&gt;Hi, I was just doing something similar, extracting a word of a string into a different variable and some words got truncated because of the default length of an array is set to 8.&lt;/P&gt;&lt;P&gt;The way to go around it is to put a really big length for the array.&lt;/P&gt;&lt;P&gt;My code is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.smallranges_desc1;&lt;BR /&gt;set work.smallranges;&lt;BR /&gt;array word {&amp;amp;maxlength.} $100.;&lt;BR /&gt;do i=1 to &amp;amp;maxlength.;&lt;BR /&gt;word[i]=scan(range,i);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 19:01:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/760987#M240721</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2021-08-11T19:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: array length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/760999#M240728</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95727"&gt;@Elle&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you may be confusing the number of occurrences of the array with the length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95727"&gt;@Elle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;array word {&amp;amp;maxlength.} $100.;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What you have in {braces} is not the length.&amp;nbsp; $100 is the length of each variable in the array.&amp;nbsp; "&amp;amp;maxlength" is not a length at all but rather is the number of occurrences in the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, let's say I have some variables in a SAS dataset.&amp;nbsp; Each variable is character.&amp;nbsp; The names of the variables are Animal1 - Animal6.&amp;nbsp; Let's say each variable is $32.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would declare the array as follows:&lt;/P&gt;
&lt;P&gt;ARRAY Animals {6} $32 Animal1 - Animal6;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The number "6" is not a length but the number of occurrences.&amp;nbsp; $32 is the length of each occurrence.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, say I have the following SAS code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Have;
	INPUT	Animal1 : $32.
			Animal2 : $32.
			Animal3 : $32.	
			Animal4 : $32.
			Animal5 : $32.	
			Animal6 : $32.
			;
DATALINES;
bird cat aardvark tarantula tapir elephant
dog owl mouse hippopotamus lamb lemur 
panda piranha parakeet pig peacock penquin
armadillo fringehead jellyfish alligator wallaby pademelon
;
RUN;

DATA	Want;
	DROP	_:;
	SET	Have;
	ARRAY	Animals {6}	$8	Animal1 - Animal6;
	DO	_i	=	1	TO	6;
		Animals{_i}	=	PROPCASE(Animals{_i});
	END;
RUN;

PROC	PRINT	DATA	=	Want;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My array definition is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;ARRAY	Animals {6}	$8	Animal1 - Animal6;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Notice my results:&amp;nbsp; Some of the names are truncated.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1628714042094.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62487iCA44FC881FDD08AF/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1628714042094.png" alt="jimbarbour_0-1628714042094.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, change the array definition from $8 to $32:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;ARRAY	Animals {6}	$32	Animal1 - Animal6;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;In the results, the truncation is gone.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_1-1628714173724.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62488i449B85FE5DE1D3A9/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_1-1628714173724.png" alt="jimbarbour_1-1628714173724.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In both of my definitions, the number of occurrences was {6}.&amp;nbsp; This did not change.&amp;nbsp; The length of each variable however did change.&amp;nbsp; It went from $8 to $32.&amp;nbsp; &lt;STRONG&gt;The length definition is what you need to change&lt;/STRONG&gt; in order to fix truncation, not the number of occurrences.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;First definition (too short):&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;ARRAY	Animals {6}	$8	Animal1 - Animal6;&lt;/CODE&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Second definition (correct) &lt;CODE class=" language-sas"&gt;ARRAY	Animals {6} $32 Animal1 - Animal6;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 20:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/760999#M240728</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-11T20:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: array length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/761318#M240890</link>
      <description>Thanks for the lengthy reply. Personally, I am not confusing anything. My &amp;amp;maxlength. was 6 which resulted in 6 new variables in my case. I was having an issue with the default length of the 6 variables, which was truncating the strings I assigned to them. The way I read OP's question, it seemed he wanted to store different lengths in his array variables so I provided my solution. If OP was referring to something else, he's have to jump to some other answer.</description>
      <pubDate>Thu, 12 Aug 2021 23:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-length/m-p/761318#M240890</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2021-08-12T23:51:49Z</dc:date>
    </item>
  </channel>
</rss>

