Date: Wed, 30 Nov 2005 10:21:21 -0800
Reply-To: chris@OVIEW.CO.UK
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: chris@OVIEW.CO.UK
Organization: http://groups.google.com
Subject: Re: Space omitted from substr()
In-Reply-To: <1133300445.352149.297110@g43g2000cwa.googlegroups.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi James,
It isn't clear exactly what you're doing here - perhaps you could post
your code? However, some notes which might clarify things,
particularly if you're new to SAS:
Character-handling in SAS is 'quirky' to say the least, particularly if
you come from another language like C or Perl. SAS doesn't have any
concept of an 'end-of-string' character. If you have a character
variable of length 10, it will always be exactly 10 characters long,
padded with spaces as necessary. For example:
length x $ 10 y $ 20;
x = 'Test';
y = x || 'String';
will give y a value of "Test String".
Apologies if you know all this already... Going back to your question,
what do you mean when you say 'substr(line,1,9) gives only "Value1"'?
I'm going to guess that the problem is that the variable you assign
substr(line,1,9) to is ending up with a length of 6, and is therefore
truncating longer values later in the data file. If so, just declare
the variable to be length 9 at the beginning of your datastep. In the
absence of an explicit declaration, character variables in SAS get
whatever length is necessary to hold the first value they are assigned.
Chris.
--------------------------------------------------------
Elvis SAS Log Analyser - http://www.oview.co.uk/elvis
--------------------------------------------------------
|