Practical Data Management
and Statistical Computing (BioEp691F)
Outline: Lec1 Lec2
Lec3 Lec4
Lec5 Lec6
Lec7 Lec8
Lec9 Lec10
Lectures: Lec1
Lec2 Lec3
Lec4
Lec5
Lec6
Lec7
Lec8
Lec9
Lec10
Lecture 3
1.
Review
- Using a SAS data set again in the same SAS Session
- Example:
- lec1sm1.sas reads in a simple
SAS data set.
- dmse99p5.sas (uses previously
created temporary SAS data set to create another SAS data
set)
- Saving a Permanent SAS Data set
- dmse99p6.sas creates permanent
SAS data set and includes a LABEL
2. Reading Data from a Previously Saved ASCII Data
File
Usually we will read in data that has been stored in a separate
ASCII file with a file name. In SAS, we specify the name of the file,
and its location with in INFILE statement. Rather than including the
data directly in the SAS program, there is reference to data file
name and location.
- Example:
- Review the program lec1sm5.sas
- Suppose data for the Weight Club has been stored in an
ASCII file called lec1sm2.txt on the C:\DATA directory. We read
the data into SAS from this file with the program dmes99p3.sas.
Avoiding Problems when Downloading a Copy of ASCII Data from
the WEB to an ASCII data file
When saving data from the WEB, formating characters that are not
visible may be included in the saved data set that later can cause
problems when reading the data into SAS. If data are saved in a
particular manner, these formating characters will be deleted in the
saved file. We illustrate two ways in which ASCII data can be saved
from the WEB, with formating characters deleted.
- Example
- Method 1 to save lec1sm2.dta on
the C:\DATA directory from the WEB:
- Open the data set by clicking on it in your WEB
browser.
- Open MS WORD. Then, in Netscape, use
SELECT ALL from
Edit Menu, and then
COPY to Copy data
into MS-WORD. Then save the file as a
.txt file with carriage returns
(ie. lec1sm2.txt)
- Method 2 to save lec1sm2.dta on
the C:\DATA directory from the WEB:
- Open Notepad (to open, from
Start, select
Programs, and then
Accessories). Then, in
Netscape, use SELECT ALL
from Edit Menu, and then
COPY to Copy data
into Notepad. Then save the file as a
.dat file with carriage returns
(ie. lec1sm2.dat)
- Examine the saved data using NOTEPAD
Problems When Downloading an ASCII data
file from the WEB:
When saving data from the WEB, formatting characters can cause
problems. We illustrate an example of the problem here.
- Save lec1sm2.dta on the C:\DATA
directory using the following:
- Open the data set by clicking on it in your WEB
browser.
- Click on the FILE pull-down menu in your WEB browser,
and then select SAVE AS, placing the file in the C:\DATA
directory with the name lec1sm2.dta.
- Copy the program dmes99p4.sas
into SAS, and run the program.
- Examine the program log (dmes99p4.log)
Discussion: The log file indicates some errors in the data
that prevent SAS from reading the last variable. Inspecting the data
in NOTEPAD reveals no problem. What's wrong? One possibility is that
there are hidden characters (ASCII characters that do not appear
on the computer screen in programs like NETSCAPE, or NOTEPAD) that
are contained in the data set, and confuse SAS. By going through the
steps above, other software will delete these special characters. We
can identify some of these characters by reading the saved data into
the SAS program window.
- In SAS, open the data set lec1sm2.dta in the program
window. You should see some characters that are not
alphanumeric.
3. Reading Data in
Column Input.
- One of the best ways to type in data
- Require data lined up in columns, easily proof read.
- Decimals and decimal points need to be consistent (see
lec3sm1a.sas, with output given by
lec3sm1a.lst)
- Reading data in column input
- Example 1 (lec3sm1.sas) (see SAS
Language Manual, p409)
- Determining Columns for writing INPUT statement using Column
input.
- Example 2. (lec3sm2.sas)
- INFILE Statement with an OBS= option and CARDS
option
- LIST statement
- Then, use the results to write the INPUT statement
(lec3sm3.sas)
4.
Example:
Reading an External ASCII File using Column Input,Getting
Contents of Dataset, and Saving the data as a Permanent Sas Data
set
- INFILE with FIRSTOBS= option.
- PROC CONTENTS
Readings:
- WEB: Read WEB pages on SAS1 -Basic, Intro and Data In
- Chapter 9: Data Documentation: INFILE, p377 (intro only), SAS
Language , Reference Version 6 First Edition.
- Chapter 3 Starting with Raw Data (column input)(pp39-44).SAS
Language and Procedures, Usage Version 6 1st edition.
- Chapter 9: Data Documentation: INPUT, Column, p407-409, SAS
Language , Reference Version 6 First Edition.
- Chapter 9: Data Documentation: INFILE, FIRSTOBS= ,OBS= option,
p382, 384, SAS Language , Reference Version 6 First Edition.
- Chapter 9: Data Documentation: LIST p437-438, SAS Language ,
Reference Version 6 First Edition.
- Chapter 12: PROC CONTENTS, pp194-199, SAS Procedures Guide,
Version 6, Third Edition.