SAS: Input Raw data with different length of character variable

data map;
infile datalines delimiter=',';
length faculty $2 progname $90. facdesc $25.;
input  faculty $ progname $ facdesc $;
datalines;
AB, AB-Digital Media, , Faculty AB
AB, AB-Interdisc. Fine Arts, Faculty AB
CD,SC-Biology,Science, Faculty CD
;
run;

NOTE:

  • Can’t use Input statement to set length for the variable.  Input statement only identify the character variables by putting $ after the variable name.
  • Use ‘,’ to separate the value of the variable in the datalines; no need to put ‘;’ to end each dataline, just end the whole datalines section with one ‘;’.
  • Put Length statement before the Input statement to set the desired variable length for the data needed input.

BENEFIT:

  • No need to use “” for character values that contain spaces.
  • No need to align the variables in datalines.

SAS: Change Variable Length in one data step

Need to put Length statement before the Set statement to change the length of existing variable. Use the LENGTH statement as the very first statement in the DATA STEP to declare the length of variable in the Set dataset.
thekey and program variables in the mapping dataset are both $7 in length.  The following data step change the length of these two variables to $10.

data mapping;
length thekey $10 program $10;
set mapping;
run;