Remember, variable
attributes are defined when the variable is first encountered in the
DATA step. In the program below, the LENGTH statement precedes the
INPUT statement and defines both the length and type of the variable
City. A length of 12 has been assigned to accommodate
PHILADELPHIA
,
which is the longest value for City.
data sasuser.growth;
infile citydata;
length City $ 12;
input city $ Pop70 Pop80;
run;
proc print data=sasuser.growth;
run;
Using this method, you
do not need to specify City's type in the INPUT statement. However,
leaving the $ in the INPUT statement does not produce an error. Your
output should now display the complete values for City.
Note: Variable attributes are defined
when the variable is first encountered in the DATA step, a variable
that is defined in a LENGTH statement (if it precedes an INPUT statement)
appears first in the data set, regardless of the order of the variables
in the INPUT statement.