|
At 19:35 27/04/00 -0400, paula wrote:
>There is this rountine assignment
>
>xyz = substr (uvwxyz, 1, 1);
>zyx = substr (uvwxyz, 2, 1);
>yxz =substr (uvwxyz, 3,1);
>
>The original variable uvwxyz is of $6. Now it is so said (not by the
>reference manual) that the length of the three new variables to the left of
>the assignment are all determined by that of the original UVWxyz.
Paula, in the absence of a prior LENGTH statement, the length of any
variable is determined by the length of the first value assigned to it.
Hence, if your above three assignment statements represented the first time
values had been assigned to xyz, zyx and yxz, all three of them would
become determined as having a length of just 1 - since the SUBSTR()
function is, in each case, resulting in assignment of a value of that length.
>So should I use a Length statement to declare the length for them first?
Yes - if you want their length to be anything other than 1.
>Is this generalizable to many other functions? such as Compress, or
>just a rule specific to this substr for a good reason?
Hopefully, the above will have explained 'the rule' to you - it's nothing
to do with what functions you use, but is a matter of what length of value
is (or may be) the first ever to be assigned to the variable in question.
For example, if the statement xyz = 'A' was the first assignment statement
involving 'xyz', if it's length had not been previously defined, it would
become 1 as a result of that assignment - as you can see from the following
log:
31 data show_it ;
32 xyz = 'A' ;
33 xyz = 'BCD' ;
34 put xyz= ;
35 run ;
XYZ=B
So ... if the length of that first assigned value is, or may be, different
from the length you want the variable to have, then, yes, you need a prior
LENGTH (or ATTRIB) statement.
Hope that helps.
Kind Regards
John
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: John.W@mediscience.co.uk
Buckingham MK18 4EL, UK mediscience@compuserve.com
----------------------------------------------------------------
|