Anda di halaman 1dari 9

Learning SAS

SAS Discussion session 1 – Data Import/Export

Getting data into SAS

Before getting into details we should understand………….

• Why do we need to read data from external sources ?

• What does SAS do when it reads the data?
• How does SAS know what to read and where to read from?
• What types of data can SAS read?
SAS can read data from almost any source. Common sources of data are
raw text files, Microsoft Office Excel spreadsheets, Access databases,
and most of the common database systems such as DB2 and Oracle….
Type of Data

Is it character or numeric…………

• How does SAS knows whether incoming data is Character or

• How to tell SAS what is nature of the data (Attributes of the Data)
Note: This has to be told to SAS or SAS would guess what is
incoming data
Can I make SAS to think for me

Is it possible to automate the processes in SAS?

• Reading data
• Importing data files
• Does Proc Import make any assumptions?
• Does Proc Import make any suggestions to itself to read
the data?
• Can we read all kind of data using Proc Import?
Various methods of reading the data

• Infile Statement with Input option ( To read External File )

• Proc Import
• Import Wizard
• Data Step
With Datalines /Cards/ Datalines;; (Reading direct data)
• Permanent SAS data
Proc Sort
SET Statement
• Accessing through ODBC using Proc SQL Connect to
• Copying an Entire Library
COPY Statement (Proc Datasets)
COPY Procedure (Proc Copy in=)
• Difference between the External File/SAS Data set
• Using Proc ACCESS
• Using Dynamic Data Exchange (DDE)
• Display Manager Command: DIMPORT
Ex: dm “DIMPORT ‘filename.csv’ replace exc;
Problems reading input files

• Reading *.txt files

 delimiters
 line feed
 tab…..
• Reading *.csv files
 Infile
Note:- *.txt/*.csv use Infile statement to read data
• Reading *.xls files
 The maximum record length is 256, one or more lines
are truncated
Export data

Output file….

• Now after reading the data you do what ever you want to
do with it , Slice it or Dice it or Smash it or Crush it or
Make a Soup with it or Make a dish with it.
• "More you harass the data, More are the Secrets it tells " .
So when you are done with Data you want to write it out .
This is out put file.
• It can be a simple SAS data set , *.csv file or *.rtf file or
Operating system Independent files *.xpt files (SAS
transport files)
Techniques of Exportin the data

Output file….

• Proc Export
• File
• Proc Copy
• Set
• .Xpt File
• ODS output out =
• Display Manager Command ( DEXPORT)
 Exports into EXCEL file;
dm "DEXPORT ‘filename.xls' replace";
 Exports into .CSV file
dm "DEXPORT ‘filename.csv”;