SAS Notes 1

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 42

1.

Overiew of SAS
Base/SAS is the core foundation for
a variety of data management and
analytical software components
offered by SAS.
1.Overiew of SAS
Base/SAS provides the essential tools for the
basic data driven tasks that are commonly
performed by a programmer.
 Data access
 Management
 Analysis
 Presentation.
1.Overiew of SAS
1.Overiew of SAS
SAS programming language is used to
 Access data from many sources
 Manage your data
 Analyse the data and present it as meaningful
information in a report that can be delivered to
any platform , in any format needed.
Data access management analysis
and presentation
1.Overiew of SAS
Accessing data:
SAS can access data
 That is stored almost anywhere whether it is
in a file on the system , or the data that is
stored on a remote server or in another
database system.
 That is almost in any format including the raw
data sets, SAS data sets and files created by
other software.
1.Overiew of SAS
Types of files that can be accessed:
Relational databases: DB2, oracle, teradata,
MS SQL server.
Non-relational database: ADABAS, PC file
formats, System 2000 software.
Enterprise resource planning (ERP) systems:
Baan, SAP BW.
1.Overiew of SAS
Managing data:
SAS programming language is used to
manipulate the data .We can use it for
formatting the data , creating the variables ,
use operators and functions to evaluate,
create and recode data values, subset the
data ,perform conditional processing merge
data sources, create , retrieve and update
database information.
1.Overiew of SAS
Analyzing data and presenting
information:
Once the data is proper ,SAS is used to
analyze data and produce reports. SAS
output can range from a simple listing of a
dataset to customized reports of complex
relationships.
1.Overiew of SAS
SAS is a powerful data analysis tool. We can
produce tables , frequency counts and cross
tabulation tables, create a variety of charts
and plots, compute a variety of descriptive
statistics , including mean , sum , variance
etc, compute correlations and other measures
of association, as well as multi-way cross
tabulations and inferential statistics.
1.Overiew of SAS
Presentation:
SAS has limitless number of visually appealing output formats ,
such as,
 An array of markup languages including HTML4 and XML.
 Output that is formatted for a high resolution printer , such as
post script , PDF, and PCL files
 RTF
 Color graphs tht can be made interactive using Active X
controls or Java applets.
these can be later sent to a variety of locations and platfoms.
2.Explore SAS workspace
When SAS is started ,five main windows
open.
 The explorer window
 The results window
 The log window
 The editor window
 The output window.
2.Explore SAS workspace
THE EXPLORER WINDOW:
This is to view and manage the SAS files and
create shortcuts to files that are not formatted
by SAS. This window is used to
 Create new SAS libraries and SAS files.
 Open any SAS file.
 Perform most file management tasks such as
moving, copying, and deleting files.
 Create shortcuts.
2.Explore SAS workspace
THE EDITOR WINDOW:
This window is used to enter, edit, and submit SAS
programs. This provides useful editor features like
 Color coding and syntax checking of SAS
language
 Expandable and collapsible sections
 Recordable macros
 Support for keyboard shortcuts
 Multilevel undo and redo.
2.Explore SAS workspace
THE LOG WINDOW:
This displays the messages about the SAS
session and any SAS programs that are
submitted.
2.Explore SAS workspace
THE OUTPUT WINDOW:
This displays the output from SAS programs
that are submitted.
NOTE: Not all SAS programs create output in
the output window. Some programs open
interactive windows. Others produce
messages in the log, and few others
produce in the results viewer window.
2.Explore SAS workspace
THE RESULTS VIEWER WINDOW:
This helps to navigate and manage the output
from SAS programs that are submitted.
2.Explore SAS workspace
Along with all these SAs provides a set of
ready-to-use solutions , applications and
tools. These are available in the tools
menu.
SAS also has online helpwhich is available
from the help menu.
3.Work with SAS data sets
Before any work is done , the data has to be in a
special form called a SAS data set.
SAS data set (or a table) is a file containing
descriptor information and related data values.
This is organized as a table of rows
(observations) and columns (variables) that can
SAS process. Some SAS datasets also contain
an index, which enables SAS to locate records in
the data set.
3.Work with SAS data sets
All SAS files are stored in a SAS library. This
is a collection of files such as SAS datasets
and catalogs.
To access a library , a name is assigned
(libref). These are the shortcuts that are
used to identify libraries during a SAS
session.
3.Work with SAS data sets
View SAS files in a library:
Go to explorer window

Double click libraries


(see three imp libraries-sashelp, sasuser, work)

Double click sashelp library

Scroll down to see several types of files in the library (sas data
set/view/catalog/MDDB)
3.Work with SAS data sets
Assign a library:
When a library is defined , location of the
SAS files to SAS is indicated. Once the
library is defined d, SAS files can be
managed within it.
3.Work with SAS data sets
On the toolbar , click new library icon

Type the name of the library

Select enable at start up

Click browse and select the location. Click ok


Assign a library
3.Work with SAS data sets
Add and rename SAS data set
With explorer window active select view | show tree. (libraries
are displayed)

Click SAShelp library

Drag the data set from the right pane and drop it into the desired
library

Click the library to find the data set in the library. Right click and
select rename and type the new name.
3.Work with SAS data sets
There are many ways to get data into SAS data set.
 Enter data directly into SAS using view table window
 Read raw data into SAS using import wizard or proc
statements
 Read and modify existing data sets using SAS programming
statements
 Convert other software data files into SAS data set by
SAS/Access
 Read other software data directly using SAS/Access
3.Work with SAS data sets
Open a SAS data set:
Select the library from the explorer window

Select the data set that is to be viewed and


worked on

Scroll the view table and notice study the data


values.
3.Work with SAS data sets
Descriptor portion of SAS:
The descriptor portion of SAS data set contains
information about the data set. This includes
 Name of the data set
 Date and time of the creation of the data set
 Number of observations
 Number of variables
3.Work with SAS data sets
View properties of data set
Right click on the data set and select properties

Click on the column tab to view the details of


the variables

The format of the column can be changed using


format option.
4.Create and run SAS programs
 The SAS language contains
statements,expressions, functionsand
CALL routines , options, formats and
informats – elements that many
programming languages share.
4.Create and run SAS programs
SAS also simplifies programming with its library of
built in programs known as SAS procedures. SAS
procedures uses data values from SAS data sets
to produce preprogrammed reports, requiring
minimal effort. BASE/SAS procedures enables to
 Manipulate data
 Store and retrieve information
 Perform statistical analysis
 Create reports.
4.Create and run SAS programs
Components of SAS programs:
SAS basically has two steps – the DATA step
and the PROC step. These two types of
steps, alone or combined, form all SAS
programs.
4.Create and run SAS programs
DATA steps typically create or modify SAS data sets.
They can also be used to produce custom
designed reports. Data steps are generally used to
 Put the data into SAS data set
 Compute the values for new variables
 Check for and correct errors in the data set.
 Produce new data sets by subsetting, merging and
updating existing datasets.
4.Create and run SAS programs
PROC (procedure) steps typically analyze and process data in
the form of a SAS data set,and they sometimes create SAS
data set that contain the results of the procedure. PROC
steps control a library of prewritten routines that perform
tasks on SAS datasets, such as listing, sorting and
summarizing the data.
PROC steps are generally used to
 Print a report
 Produce descriptive statistics
 Create a tabular report
 Produce plots and charts
4.Create and run SAS programs
Characterization of SAS programs:
SAS programs are made up of SAS statements. A
SAS statement has two important characteristics-
 It begins with a keyword.
 It ends with a semicolon.
A data step begins with the keyword DATA and the
proc step begins with keyword PROC. Ends with
a RUN statement which tells SAS to process all
the preceding lines of the step.
4.Create and run SAS programs
SAS statements are free format.
 They can begin and end anywhere on a line.
 One statement can continue over several
lines
 Several statements can be run on a line.
SAS statements are not case sensitive. Blanks
or special characters separate the words in a
SAS statement.
4.Create and run SAS programs
Copy a SAS program into the editor window:
Define the library

Create the dataset

Copy a sample SAS program in the editor window


(notice SAS keywords are color coded and the
program steps separated into expandable
blocks.
4.Create and run SAS programs
Submit the program and view the output:
When a program is submitted ,SAS compiles and executes the
code and returns any results to the output window.
With the editor window active select run|submit.

View the log:


Each time a step is executed , SAS generates a log of
processing activities and the results of the processing. The
SAS log collects messages about the processing of SAS
programs and any errors that may occur.
Click the log window to activate the log.
4.Create and run SAS programs
Use the results window:
Once the output is created , the results
window opens. The results node at the top
of the window contains a folder for the
output of the procedure. The folder is
labeled with the procedure name and the
title of the report.
4.Create and run SAS programs
Create HTML output:
Select tools > options > preferences.

Click the results tab.

Select the ‘create HTML’ check box.

Click ok.
4.Create and run SAS programs
Modify the program:
We can add options to the programs to
 Remove the date from the top of each page.
 Replace the default ‘the SAS system title’.
 Use the column label rather than the
column name in the output.
 Remove the obs column.
4.Create and run SAS programs
 To remove date from the top of each page use
NODATE system option and paste it at the top of
the program.
options nodate;
 To replace the default title , use TITLE statement.
title “ life is beautiful”;
 To remove obs column and use column labels,
use options on PROC PRINT statement.
Proc print data=xyz label noobs;
4.Create and run SAS programs
View and Save results:
HTML results can be created and saved in HTML files.
In the results window, scroll the HTML results.

With results viewer window active, select file > save as. In the
filename box, type the name and click save.

The results window now shows a new folder for the results of
the program .double click on the folder to view the output.
4.Create and run SAS
Save a SAS program and set up a favorite folder:
programs
When SAS programs are saved , we can store them in a folder that is easy to
access from the explorer window.
With the editor window active, select file > save as.

This opens to default folder on the system . In filename box , type the name
and click save. The file is saved with a .sas extension, indicating that it is a
SAS program.

In explorer window, double click favorite folders

Right click in the favorite folders window and select new favorite folder.

In the new favorite folder window type , type folder name in the name box.

Click browse. The select window opens to the same default location where the
program was saved. Click ok.

You might also like