LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2000, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 28 Apr 2000 03:24:58 +0100
Reply-To:   John Whittington <John.W@MEDISCIENCE.CO.UK>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   John Whittington <John.W@MEDISCIENCE.CO.UK>
Subject:   Re: length of variable assigned to substr function.
Comments:   To: paula <icj808@USWEST.NET>
In-Reply-To:   <200004280144.CAA12315@vicar.netnames.net>
Content-Type:   text/plain; charset="us-ascii"

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 ----------------------------------------------------------------


Back to: Top of message | Previous page | Main SAS-L page