You can
use the LENGTH statement to create a variable and set the length of
the variable, as in the following example:
data sales;
length Salesperson $20;
run;
For character variables,
you must use the longest possible value in the first statement that
uses the variable, because you cannot change the length with a subsequent
LENGTH statement within the same DATA step. The maximum length of
any character variable in SAS is 32,767 bytes. For numeric variables,
you can change the length of the variable by using a subsequent LENGTH
statement.
When SAS assigns a value
to a character variable, it pads the value with blanks or truncates
the value on the right side, if necessary, to make it match the length
of the target variable. Consider the following statements:
length address1 address2 address3 $ 200;
address3=address1||address2;
Because the length of
ADDRESS3 is 200 bytes, only the first 200 bytes of the concatenation
(the value of ADDRESS1) are assigned to ADDRESS3. You might be able
to avoid this problem by using the TRIM function to remove trailing
blanks from ADDRESS1 before performing the concatenation, as follows:
address3=trim(address1)||address2;