O'Reilly logo

Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition by SAS Institute

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The only restriction is that at least two blanks must divide each value from the next data
value in the record.
To use the ampersand format modifier with list input, place the ampersand between the
variable name and the informat. The following DATA step uses the ampersand format
modifier with list input to create the data set CLUB2. Note that the data is not in fixed
columns. Therefore, column input is not appropriate.
data club2;
input IdNumber Name & $18. Team $ StartWeight EndWeight;
datalines;
1023 David Shaw red 189 165
1049 Amelia Serrano yellow 145 124
1219 Alan Nance red 210 192
1246 Ravi Sinha yellow 194 177
1078 Ashley McKnight red 127 118
1221 Jim Brown yellow 220 .
;
proc print data=club2;
title 'Weight Club Members';
run;
The character variable Name, with a length of 18, contains members' first and last names
separated by one blank space. The data lines must have two blank spaces between the
values for the variable Name and the variable Team for the INPUT statement to correctly
read the data.
The following output displays the resulting data set:
Figure 4.12 Data Set Created with Modified List Input (& $18.)
Mixing Styles of Input
An Example of Mixed Input
When you begin an INPUT statement in a particular style (list, column, or formatted),
you are not restricted to using that style alone. You can mix input styles in a single
Mixing Styles of Input 65
INPUT statement as long as you mix them in a way that appropriately describes the raw
data records. For example, this DATA step uses all three input styles:
data club1;
input IdNumber 1
Name $18. 2
Team $ 25-30 3
StartWeight EndWeight;
datalines; 1
1023 David Shaw red 189 165
1049 Amelia Serrano yellow 145 124
1219 Alan Nance red 210 192
1246 Ravi Sinha yellow 194 177
1078 Ashley McKnight red 127 118
1221 Jim Brown yellow 220 .
;
proc print data=club1;
title 'Weight Club Members';
run;
The following list corresponds to the numbered items in the preceding program:
1
The variables IdNumber, StartWeight, and EndWeight are read with list input.
2
The variable Name is read with formatted input.
3
The variable Team is read with column input.
The following output demonstrates that the data is read correctly.
Figure 4.13 Data Set Created with Mixed Styles of Input
Understanding the Effect of Input Style on Pointer Location
Why You Can Get into Trouble By Mixing Input Styles
CAUTION:
When you mix styles of input in a single INPUT statement, you can get
unexpected results if you do not understand where the input pointer is
positioned after SAS reads a value in the input buffer. As the INPUT statement
reads data values from the record in the input buffer, it uses a pointer to keep track of
its position. Read the following sections so that you understand how the pointer
66 Chapter 4 Starting with Raw Data: The Basics

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required