Professional Documents
Culture Documents
Section 1
1.
2.
3.
4.
We will be talking about this method a lot during this chapter and the next couple of
chapters.
INFILE Statement
INFILE statement
Format:
DATA <dataset_name>;
INFILE <path_of_the_file>;
INPUT <names_of_variables>;
It is also called list input because of the format of the statement. The variable names are
listed in the INPUT statement by the order of appearance in the data set.
Character
$informatw.
Numeric Date
informatw.d
informatw.
Example 2.1.3
This example illustrates the use of informats for reading data. The following data file,
Pumpkin.dat, represents the results from a local pumpkin-carving contest. Each line includes the
contestants name, age, type (carved or decorated), the date the pumpkin was entered, and the
scores from each of five judges.
Alicia Grossman 13 c 10-28-2008 7.8 6.5 7.2 8.0 7.9
Matthew Lee 9 D 10-30-2008 6.5 5.9 6.8 6.0 8.1
Elizabeth Garcia 10 C 10-29-2008 8.9 7.9 8.5 9.0 8.8
Lori Newcombe 6 D 10-30-2008 6.7 5.6 4.9 5.2 6.1
Jose Martinez 7 d 10-31-2008 8.9 9.510.0 9.7 9.0
Brian Williams 11 C 10-29-2008 7.8 8.4 8.5 7.9 8.0
Column Pointer @
Try to import NatPark.dat file to SAS by writing your code. (OPTIONAL but good exercise)
Try to use all the methods we have learned so far. Use list input, column input, informats and
column pointer in the same INPUT statement.
There is no single correct solution for the problem. Use your imagination. The output should
look something like this:
FIRSTOBS =
OBS =
MISSOVER
TRUNCOVER
DLM =
DSD
************ OR **********
Data animals;
input Zooname $ Tigers Lions Monkeys;
Datalines;
San_Diego 7 4 23
New_York 11 4 37
Orlando 2 8 41
;
Section 2
libref
(library reference)
member name
This information is hidden in where you put your data set. If it is in WORK library, then
it is temporary. Else, it is permanent.
This also means that if you dont specify a libname with your data, it will be temporary
because it goes to WORK library as WORK library is the default.
Example
Data Statement
Libref
Member name
Type
DATA ironman;
WORK
ironman
temporary
DATA WORK.ironman;
WORK
ironman
temporary
DATA Bikes.ironman;
Bikes
ironman
permanent
DATA distance;
Miles = 26.22;
Kilometers = 1.61 * Miles;
RUN;
PROC PRINT DATA = distance;
RUN;
Temporary
DATA Bikes.distance;
Miles = 26.22;
Kilometers = 1.61 * Miles;
RUN;
PROC PRINT DATA = Bikes.distance;
RUN;
Permanent
LIBNAME Statement
You can also define a libref using the New Library window.
Example 2.2.1
This program sets up a libref named PLANTS pointing to the BaseData directory.
Then it reads the raw data from a file called Mag.dat, creating a permanent SAS data
set named MAGNOLIA which is stored in the PLANTS library.
Example 2.2.2
You can also read into and from any file by direct referencing.
Further Reading
Optional: Read The Little SAS Book Chapter 2.12 2.18 for more advanced data
parsing methods