Date: Tue, 2 Jun 1998 20:31:25 +1000
Reply-To: Tim Churches <tchurch@IBM.NET>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Tim Churches <tchurch@IBM.NET>
Subject: SAS Trap: ordering of FORMAT= in ATTRIB statement
Content-Type: text/plain; charset=us-ascii
This was a new one on me: the order in which FORMAT= is used an ATTRIB
statement affects the length of character variable. Easier to illustrate
than explain:
************************* ;
proc format ;
value $bug
'0000' = 'This must be a bug'
other = 'Or maybe a feature' ;
run ;
data test1 ;
attrib testvar length=$4 format=$bug. ;
testvar = '0000' ;
run ;
data test2 ;
attrib testvar format=$bug. length=$4 ;
testvar = '0000' ;
run ;
proc contents data=test1 ;
run ;
proc contents data=test2 ;
run ;
************************* ;
You would expect the variable testvar to have a length of 4 in both
test1 and test2 datasets, no? Wrong! Testvar is assigned a length of 4
in the first dataset, but a length of 18 in the second dataset, even
though the only difference between the two data steps which create the
datasets is the position of the FORMAT= in the ATTRIB statement. I have
tried this under 6.08 for VAX/VMS, 6.11 for Unix and 6.12 TS045 for
Windows, all with the same results. I can't find any mention in the
manuals that the order of FORMAT= and LENGTH= in an ATTRIB statement is
important, but clearly it is.
Tim Churches