SlideShare una empresa de Scribd logo
1 de 16
Introduction

To program effectively using SAS, you need to understand basic concepts about SAS
programs and the SAS files that they process. In particular, you need to be familiar
with SAS data sets.

In this lesson, you'll examine a simple SAS program and see how it works. You'll learn
details about SAS data sets (which are files that contain data that is logically arranged
in a form that SAS can understand). Finally, you'll see how SAS data sets are stored
temporarily or permanently in SAS libraries.




Editor

This window is a text editor. You can use it to type in, edit, and submit SAS programs as
well as edit other text files such as raw data files. In Windows operating environments,
the default editor is the Enhanced Editor. The Enhanced Editor is syntax sensitive and
color codes your programs making it easier to read and find mistakes. The Enhanced
Editor also allows you to collapse and expand the various steps in your program. For
other operating environments, the default editor is the Program Editor whose features
vary with the version of SAS and operating environment.
Log

The Log window contains notes about your SAS session, and after you submit a SAS
program, any notes, errors, or warnings associated with your program as well as the
program statements themselves will appear in the Log window.

Output

If your program generates any printable results, then they will appear in the Output
window.

Results

The Results window is like a table of contents for your Output window; the results tree
lists each part of your results in an outline form.

Explorer

The Explorer window gives you easy access to your SAS files and libraries.

 SAS Programs

 Layout of SAS programs

There really aren’t any rules about how to format your SAS program.

    While it is helpful to have a neat looking program with each statement on a line by
itself and indentions to show the various parts of the program, it isn’t necessary.

1.   SAS statements can be in upper- or lowercase.
2.   Statements can continue on the next line (as long as you don’t split words in two).
3.   Statements can be on the same line as other statements.
4.   Statements can start in any column.

 The Two Parts of a SAS Program
DATA steps                                        PROC steps

1. Begin with DATA statements              1. Begin with PROC statements
2. Read and modify data                    2. Perform specific analysis or function
3. Create a SAS data set                   3. Produce results or report

Sample program

Data work.clinic;
Input Name$ Age Gender$;
Cards;
Shilpa 23 female
Ravi 24 male
Pradip 24 male
Sweta 23 female
Run;


Characteristics of SAS Programs

Next let's look at the individual statements in our sample program. SAS programs consist
of SAS statements. A SAS statement has two important characteristics:

   •   It usually begins with a SAS keyword.
   •   It always ends with a semicolon.




              Statements         Sample Program Code
           a DATA statement DATA work.clinic;
           a INPUT statement Input Name$ Age Gender$;
           a CARDS statement Cards;
           a RUN Statement         Run;


Issue the SUBMIT command or click on Submit or select Run _ Submit to submit the
program for execution.
Data types

Raw data come in many different forms, but SAS simplifies this. In SAS there are just
two data types: numeric and character. Numeric fields are, well, numbers. They can be
added and subtracted, can have any number of decimal places, and can be positive or
negative. In addition to numerals, numeric fields can contain plus signs (+), minus signs
(-), decimal points (.), or E for scientific notation. Character data are everything else.
They may contain numerals, letters, or special characters (such as $ or !) and can be up to
32,767 characters long.

Rules for SAS names

You make up names for the variables in your data and for the data sets themselves. It is
helpful to make up names that identify what the data represent, especially for variables.
While the variable names A, B, and C might seem like perfectly fine, easy-to-type names
when you write your program, the names Sex, Height, and Weight will probably be more
helpful when you go back to look at the program six months later. Follow these simple
rules when making up names for variables and data set members:

     1. Names must be 32 characters or fewer in length.3
     2. Names must start with a letter or an underscore (_).
     3. Names can contain only letters, numerals, or underscores (_). No %$!*&#@,
        please.4
     4. Names can contain upper- and lowercase letters.

Reading the SAS Log

Every time you run a SAS job, SAS writes messages in your log. Many SAS
programmers ignore the SAS log and go straight to the output. That’s understandable, but
dangerous. It is possible and sooner or later it happens to all of us to get bogus results that
look fine in the output. The only way to know they are bad is to check the SAS log. Just
because it runs doesn’t mean its right.

 1     DATA work.clinic;
 2     Input Name$ Age Gender$;
 3     Cards;

 NOTE: The data set WORK.CLINIC has 4 observations and 3 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.31 seconds
       cpu time            0.00 seconds

 8     Run;
SAS Data Sets

  Overview of SAS Data Sets

As you saw in our sample program, for many of the data processing tasks that you
perform with SAS, you

   •   Access data in the form of a SAS data set
   •   Analyze, manage, or present the data.

Conceptually, a SAS data set is a file that consists of two parts: a descriptor portion and
a data portion. Sometimes a SAS data set also points to one or more indexes, which
enable SAS to locate records in the data set more efficiently. (The data sets that you work
with in this lesson do not contain indexes.)




Length

A variable's length (the number of bytes used to store it) is related to its type.

   •   Character variables can be up to 32K long.
   •   All numeric variables have a default length of 8. Numeric values (no matter how
       many digits they contain) are stored as floating-point numbers in 8 bytes of
       storage, unless you specify a different length.
Missing data

Sometimes despite your best efforts, your data may be incomplete. The value of a
particular variable may be missing for some observations. In those cases, missing
character data are represented by blanks, and missing numeric data are represented by a
single period (.).

Size of SAS data sets

Prior to SAS 9.1, SAS data sets could contain up to 32,767 variables.

Beginning with SAS 9.1, the maximum number of variables in a SAS data set is limited
by the resources available on your computer but SAS data sets with more than 32,767
variables cannot be used with earlier versions of SAS. The number of observations, no
matter which version of SAS you are using, is limited only by your computer’s capacity
to handle and store them.


SAS Libraries




Sashelp
A permanent library, that contains sample data and other files which control how SAS
works at your site. This is a read-only library.



Sasuser
A permanent library that contains SAS files in the Profile catalogs that store your
personal settings. This is also a convenient place to store your own files.

Work
A temporary library for files that do not need to be saved from session to session.

Creating a new library

You can create new SAS libraries using the New Library window. To open this window,
either left click in the Active Libraries window (to make it active) and choose New from
the File menu, or right click in the Active Libraries window and choose New from the
pop-up menu.
In the New Library window, type the name of the library you want to create. This name is
called a libref which is short for library reference. A libref must be eight characters or
fewer; start with a letter or underscore; and contain only letters, numerals, or underscores.
In this window, the name Mylib has been typed in as the libref. In the Path field, enter the
complete path to the folder or directory where you want your data sets to be stored, or
choose the Browse… button to navigate to the location. If you don’t want to define your
library reference every time you start up SAS, then check the Enable at startup box. Click
OK and then your new library reference will appear in the Active Libraries window. Here
is the Active Libraries window showing the newly created Mylib library.
                                            OR

Libname Mylib ‘D: ’;         - in Editor Window.




                               Deleting Data sets

                              Proc datasets library = SAS library name;
                              Delete SAS-dataset list;
                              Run;

                               Properties of Data sets
PROC CONTENTS DATA = SAS-file-specification NODS;
RUN;

SAS-file-specification specifies an entire library or a specific SAS data set within a
library. SAS-file-specification can take one of the following forms:

           o   <libref.>SAS-data-set names one SAS data set to process.

           o   <libref.>_ALL_ requests a listing of all files in the library. (Use a
               period (.) to append _ALL_ to the libref.)

   •    NODS suppresses the printing of detailed information about each file when you
        specify _ALL_. (You can specify NODS only when you specify _ALL_.)




       Selected Menus (as displayed in the Windows operating environment)

       Select items from this menu ...                                 To ...
open main SAS windows.

From the Explorer window, you can
use this menu to show or hide details
and a tree view.




submit and recall SAS programming
statements in the Program Editor
window.




access ready-to-use solutions and
applications.
get more help.




SAS System Options


If you create your procedure output as a SAS listing, you can also control the appearance
of your output by setting system options such as

   •   line size (the maximum width of the log and output)
   •   page size (the number of lines per printed page of output)
   •   The display of page numbers.
   •   The display of date and time.

Not all options are available for all operating environments. A list of options specific to
your operating environment appears in the SAS Help and Documentation. You can see a
list of system options and their current values by opening the SAS System Options
window or by using the OPTIONS procedure. To use the OPTIONS procedure, submit
the following SAS program and view the results in the SAS log:

PROC OPTIONS;
RUN;
Common options

The following are some common system options you might want to use:

CENTER | NOCENTER               Controls whether output are centered or left-justified.
                                Default: CENTER.

DATE | NODATE                   Controls whether or not today’s date will appear at the
                                top of each page of output.
                                Default: DATE.

LINESIZE = n                    Controls the maximum length of output lines.
                                Possible values for n are 64 to 256. Default varies.

NUMBER | NONUMBER               Controls whether or not page numbers appear on each
                                page of SAS output. Default: NUMBER.

ORIENTATION = PORTRAIT Specifies the orientation for printing output.
ORIENTATION = LANDSCAPE Default: PORTRAIT

PAGENO = n                      Starts numbering output pages with n. Default is 1.

PAGESIZE = n                   Controls the maximum number of lines per page of
                               output. Possible values for n are 15 to 32767.
                                Default varies.

RIGHTMARGIN = n                 Specifies size of margin (such as 0.75in or 2cm) to be
LEFTMARGIN = n                  printing output. Default: 0.00in.
TOPMARGIN = n
BOTTOMMARGIN = n
Extraction of Data

Extraction from notepad

Create notepad file with the name of sales and put following data…
For extraction of data from notepad write program in Editor Window of SAS.

Create file in notepad with following data with name of
Sales

Chocolate 213 123
Vanilla 213 512
Chocolate 415 242


Write following program in SAS Editor Window.


DATA icecream;
INFILE ’c:MyRawDataSales.txt’;
INPUT Flavor $ 1-9 Location BoxesSold;
RUN;


Extraction from Excel

Using the Import Wizard1, you can read a variety of data file types into SAS by simply
answering a few questions. The Import Wizard will scan your file to determine variable
types2 and will, by default, use the first row of data for the variable names. Start the
Import Wizard by choosing Import Data… from the File menu. Select the type of file you
are importing by choosing from the list of standard data sources such as Excel 97, excel
2000, etc...

                                         OR

Proc import file = ‘path of excel file’ out = sas-data set name;
Run;
SET – copying datasets

The SET statement is flexible and has a variety of uses in SAS programming. These uses
are determined by the options and statements that you use with the SET statement. They
include

   •   reading observations and variables from existing SAS data sets for further
       processing in the DATA step
   •   concatenating and interleaving data sets, and performing one-to-one reading of
       data sets
   •   Reading SAS data sets by using direct access methods.

Data test;
Set Sashelp.Air;
Run;


FIRSTOBS= The FIRSTOBS= option tells SAS at what line to begin reading data.

Data test;
Set Sashelp.air (firstobs = 10);
Run;

OBS= The OBS= option can be used anytime you want to read only a part of your data
file. It tells SAS to stop reading when it gets to that line in the raw data file.

Data test;
Set Sashelp.air (obs = 10);
Run;



Data test;
Set sashelp.class(firstobs =5 obs = 10);
Run;

In above example, work.test having 6 observations.

Más contenido relacionado

La actualidad más candente

Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sas
halasti
 
Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3
Mark Tabladillo
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
Dr P Deepak
 
Sas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary ToolSas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary Tool
sysseminar
 
Sas short course_presentation_11-4-09
Sas short course_presentation_11-4-09Sas short course_presentation_11-4-09
Sas short course_presentation_11-4-09
Prashant Ph
 

La actualidad más candente (20)

Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sas
 
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
 
Learn SAS Programming
Learn SAS ProgrammingLearn SAS Programming
Learn SAS Programming
 
SAS Programming Notes
SAS Programming NotesSAS Programming Notes
SAS Programming Notes
 
SAS Internal Training
SAS Internal TrainingSAS Internal Training
SAS Internal Training
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sas
 
Sas Statistical Analysis System
Sas Statistical Analysis SystemSas Statistical Analysis System
Sas Statistical Analysis System
 
SAS basics Step by step learning
SAS basics Step by step learningSAS basics Step by step learning
SAS basics Step by step learning
 
Sas training in hyderabad
Sas training in hyderabadSas training in hyderabad
Sas training in hyderabad
 
Table of Contents - Practical Business Analytics using SAS
Table of Contents - Practical Business Analytics using SAS Table of Contents - Practical Business Analytics using SAS
Table of Contents - Practical Business Analytics using SAS
 
Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
 
Sas Macro Examples
Sas Macro ExamplesSas Macro Examples
Sas Macro Examples
 
Sas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary ToolSas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary Tool
 
Sas summary guide
Sas summary guideSas summary guide
Sas summary guide
 
Sas short course_presentation_11-4-09
Sas short course_presentation_11-4-09Sas short course_presentation_11-4-09
Sas short course_presentation_11-4-09
 
BAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 LectureBAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 Lecture
 
BAS 150 Lesson 3 Lecture
BAS 150 Lesson 3 LectureBAS 150 Lesson 3 Lecture
BAS 150 Lesson 3 Lecture
 
BAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 LectureBAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 Lecture
 
Rational Publishing Engine and Rational System Architect
Rational Publishing Engine and Rational System ArchitectRational Publishing Engine and Rational System Architect
Rational Publishing Engine and Rational System Architect
 

Similar a Introduction to SAS

Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8
thotakoti
 
Hechsp 001 Chapter 3
Hechsp 001 Chapter 3Hechsp 001 Chapter 3
Hechsp 001 Chapter 3
Brian Kelly
 
I need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdfI need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdf
Madansilks
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sas
Dr P Deepak
 
Base sas 2 sas windowing environment
Base sas 2  sas windowing environmentBase sas 2  sas windowing environment
Base sas 2 sas windowing environment
singhvikram549
 
Spss tutorial 1
Spss tutorial 1Spss tutorial 1
Spss tutorial 1
debataraja
 

Similar a Introduction to SAS (20)

Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8
 
8323 Stats - Lesson 1 - 03 Introduction To Sas 2008
8323 Stats - Lesson 1 - 03 Introduction To Sas 20088323 Stats - Lesson 1 - 03 Introduction To Sas 2008
8323 Stats - Lesson 1 - 03 Introduction To Sas 2008
 
Basics of SAS
Basics of SASBasics of SAS
Basics of SAS
 
Analytics with SAS
Analytics with SASAnalytics with SAS
Analytics with SAS
 
Hechsp 001 Chapter 3
Hechsp 001 Chapter 3Hechsp 001 Chapter 3
Hechsp 001 Chapter 3
 
I need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdfI need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdf
 
SAS_Overview_Short.pptx
SAS_Overview_Short.pptxSAS_Overview_Short.pptx
SAS_Overview_Short.pptx
 
Important SAS Tips and Tricks for A Grade
Important SAS Tips and Tricks for A GradeImportant SAS Tips and Tricks for A Grade
Important SAS Tips and Tricks for A Grade
 
Spss basics tutorial
Spss basics tutorialSpss basics tutorial
Spss basics tutorial
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sas
 
Spss
SpssSpss
Spss
 
SAS Commands
SAS CommandsSAS Commands
SAS Commands
 
Base sas 2 sas windowing environment
Base sas 2  sas windowing environmentBase sas 2  sas windowing environment
Base sas 2 sas windowing environment
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 
6967176.ppt
6967176.ppt6967176.ppt
6967176.ppt
 
Readme
ReadmeReadme
Readme
 
Spss tutorial 1
Spss tutorial 1Spss tutorial 1
Spss tutorial 1
 
Spss tutorial 1
Spss tutorial 1Spss tutorial 1
Spss tutorial 1
 
5116427.ppt
5116427.ppt5116427.ppt
5116427.ppt
 
Top 140+ Advanced SAS Interview Questions and Answers.pdf
Top 140+ Advanced SAS Interview Questions and Answers.pdfTop 140+ Advanced SAS Interview Questions and Answers.pdf
Top 140+ Advanced SAS Interview Questions and Answers.pdf
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

Introduction to SAS

  • 1. Introduction To program effectively using SAS, you need to understand basic concepts about SAS programs and the SAS files that they process. In particular, you need to be familiar with SAS data sets. In this lesson, you'll examine a simple SAS program and see how it works. You'll learn details about SAS data sets (which are files that contain data that is logically arranged in a form that SAS can understand). Finally, you'll see how SAS data sets are stored temporarily or permanently in SAS libraries. Editor This window is a text editor. You can use it to type in, edit, and submit SAS programs as well as edit other text files such as raw data files. In Windows operating environments, the default editor is the Enhanced Editor. The Enhanced Editor is syntax sensitive and color codes your programs making it easier to read and find mistakes. The Enhanced Editor also allows you to collapse and expand the various steps in your program. For other operating environments, the default editor is the Program Editor whose features vary with the version of SAS and operating environment.
  • 2. Log The Log window contains notes about your SAS session, and after you submit a SAS program, any notes, errors, or warnings associated with your program as well as the program statements themselves will appear in the Log window. Output If your program generates any printable results, then they will appear in the Output window. Results The Results window is like a table of contents for your Output window; the results tree lists each part of your results in an outline form. Explorer The Explorer window gives you easy access to your SAS files and libraries. SAS Programs Layout of SAS programs There really aren’t any rules about how to format your SAS program. While it is helpful to have a neat looking program with each statement on a line by itself and indentions to show the various parts of the program, it isn’t necessary. 1. SAS statements can be in upper- or lowercase. 2. Statements can continue on the next line (as long as you don’t split words in two). 3. Statements can be on the same line as other statements. 4. Statements can start in any column. The Two Parts of a SAS Program
  • 3. DATA steps PROC steps 1. Begin with DATA statements 1. Begin with PROC statements 2. Read and modify data 2. Perform specific analysis or function 3. Create a SAS data set 3. Produce results or report Sample program Data work.clinic; Input Name$ Age Gender$; Cards; Shilpa 23 female Ravi 24 male Pradip 24 male Sweta 23 female Run; Characteristics of SAS Programs Next let's look at the individual statements in our sample program. SAS programs consist of SAS statements. A SAS statement has two important characteristics: • It usually begins with a SAS keyword. • It always ends with a semicolon. Statements Sample Program Code a DATA statement DATA work.clinic; a INPUT statement Input Name$ Age Gender$; a CARDS statement Cards; a RUN Statement Run; Issue the SUBMIT command or click on Submit or select Run _ Submit to submit the program for execution.
  • 4. Data types Raw data come in many different forms, but SAS simplifies this. In SAS there are just two data types: numeric and character. Numeric fields are, well, numbers. They can be added and subtracted, can have any number of decimal places, and can be positive or negative. In addition to numerals, numeric fields can contain plus signs (+), minus signs (-), decimal points (.), or E for scientific notation. Character data are everything else. They may contain numerals, letters, or special characters (such as $ or !) and can be up to 32,767 characters long. Rules for SAS names You make up names for the variables in your data and for the data sets themselves. It is helpful to make up names that identify what the data represent, especially for variables. While the variable names A, B, and C might seem like perfectly fine, easy-to-type names when you write your program, the names Sex, Height, and Weight will probably be more helpful when you go back to look at the program six months later. Follow these simple rules when making up names for variables and data set members: 1. Names must be 32 characters or fewer in length.3 2. Names must start with a letter or an underscore (_). 3. Names can contain only letters, numerals, or underscores (_). No %$!*&#@, please.4 4. Names can contain upper- and lowercase letters. Reading the SAS Log Every time you run a SAS job, SAS writes messages in your log. Many SAS programmers ignore the SAS log and go straight to the output. That’s understandable, but dangerous. It is possible and sooner or later it happens to all of us to get bogus results that look fine in the output. The only way to know they are bad is to check the SAS log. Just because it runs doesn’t mean its right. 1 DATA work.clinic; 2 Input Name$ Age Gender$; 3 Cards; NOTE: The data set WORK.CLINIC has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.31 seconds cpu time 0.00 seconds 8 Run;
  • 5. SAS Data Sets Overview of SAS Data Sets As you saw in our sample program, for many of the data processing tasks that you perform with SAS, you • Access data in the form of a SAS data set • Analyze, manage, or present the data. Conceptually, a SAS data set is a file that consists of two parts: a descriptor portion and a data portion. Sometimes a SAS data set also points to one or more indexes, which enable SAS to locate records in the data set more efficiently. (The data sets that you work with in this lesson do not contain indexes.) Length A variable's length (the number of bytes used to store it) is related to its type. • Character variables can be up to 32K long. • All numeric variables have a default length of 8. Numeric values (no matter how many digits they contain) are stored as floating-point numbers in 8 bytes of storage, unless you specify a different length.
  • 6. Missing data Sometimes despite your best efforts, your data may be incomplete. The value of a particular variable may be missing for some observations. In those cases, missing character data are represented by blanks, and missing numeric data are represented by a single period (.). Size of SAS data sets Prior to SAS 9.1, SAS data sets could contain up to 32,767 variables. Beginning with SAS 9.1, the maximum number of variables in a SAS data set is limited by the resources available on your computer but SAS data sets with more than 32,767 variables cannot be used with earlier versions of SAS. The number of observations, no matter which version of SAS you are using, is limited only by your computer’s capacity to handle and store them. SAS Libraries Sashelp A permanent library, that contains sample data and other files which control how SAS works at your site. This is a read-only library. Sasuser
  • 7. A permanent library that contains SAS files in the Profile catalogs that store your personal settings. This is also a convenient place to store your own files. Work A temporary library for files that do not need to be saved from session to session. Creating a new library You can create new SAS libraries using the New Library window. To open this window, either left click in the Active Libraries window (to make it active) and choose New from the File menu, or right click in the Active Libraries window and choose New from the pop-up menu.
  • 8. In the New Library window, type the name of the library you want to create. This name is called a libref which is short for library reference. A libref must be eight characters or fewer; start with a letter or underscore; and contain only letters, numerals, or underscores. In this window, the name Mylib has been typed in as the libref. In the Path field, enter the complete path to the folder or directory where you want your data sets to be stored, or choose the Browse… button to navigate to the location. If you don’t want to define your library reference every time you start up SAS, then check the Enable at startup box. Click OK and then your new library reference will appear in the Active Libraries window. Here is the Active Libraries window showing the newly created Mylib library. OR Libname Mylib ‘D: ’; - in Editor Window. Deleting Data sets Proc datasets library = SAS library name; Delete SAS-dataset list; Run; Properties of Data sets
  • 9. PROC CONTENTS DATA = SAS-file-specification NODS; RUN; SAS-file-specification specifies an entire library or a specific SAS data set within a library. SAS-file-specification can take one of the following forms: o <libref.>SAS-data-set names one SAS data set to process. o <libref.>_ALL_ requests a listing of all files in the library. (Use a period (.) to append _ALL_ to the libref.) • NODS suppresses the printing of detailed information about each file when you specify _ALL_. (You can specify NODS only when you specify _ALL_.) Selected Menus (as displayed in the Windows operating environment) Select items from this menu ... To ...
  • 10. open main SAS windows. From the Explorer window, you can use this menu to show or hide details and a tree view. submit and recall SAS programming statements in the Program Editor window. access ready-to-use solutions and applications.
  • 11. get more help. SAS System Options If you create your procedure output as a SAS listing, you can also control the appearance of your output by setting system options such as • line size (the maximum width of the log and output) • page size (the number of lines per printed page of output) • The display of page numbers. • The display of date and time. Not all options are available for all operating environments. A list of options specific to your operating environment appears in the SAS Help and Documentation. You can see a list of system options and their current values by opening the SAS System Options window or by using the OPTIONS procedure. To use the OPTIONS procedure, submit the following SAS program and view the results in the SAS log: PROC OPTIONS; RUN;
  • 12. Common options The following are some common system options you might want to use: CENTER | NOCENTER Controls whether output are centered or left-justified. Default: CENTER. DATE | NODATE Controls whether or not today’s date will appear at the top of each page of output. Default: DATE. LINESIZE = n Controls the maximum length of output lines. Possible values for n are 64 to 256. Default varies. NUMBER | NONUMBER Controls whether or not page numbers appear on each page of SAS output. Default: NUMBER. ORIENTATION = PORTRAIT Specifies the orientation for printing output. ORIENTATION = LANDSCAPE Default: PORTRAIT PAGENO = n Starts numbering output pages with n. Default is 1. PAGESIZE = n Controls the maximum number of lines per page of output. Possible values for n are 15 to 32767. Default varies. RIGHTMARGIN = n Specifies size of margin (such as 0.75in or 2cm) to be LEFTMARGIN = n printing output. Default: 0.00in. TOPMARGIN = n BOTTOMMARGIN = n
  • 13. Extraction of Data Extraction from notepad Create notepad file with the name of sales and put following data… For extraction of data from notepad write program in Editor Window of SAS. Create file in notepad with following data with name of Sales Chocolate 213 123 Vanilla 213 512 Chocolate 415 242 Write following program in SAS Editor Window. DATA icecream; INFILE ’c:MyRawDataSales.txt’; INPUT Flavor $ 1-9 Location BoxesSold; RUN; Extraction from Excel Using the Import Wizard1, you can read a variety of data file types into SAS by simply answering a few questions. The Import Wizard will scan your file to determine variable types2 and will, by default, use the first row of data for the variable names. Start the Import Wizard by choosing Import Data… from the File menu. Select the type of file you are importing by choosing from the list of standard data sources such as Excel 97, excel 2000, etc... OR Proc import file = ‘path of excel file’ out = sas-data set name; Run;
  • 14.
  • 15.
  • 16. SET – copying datasets The SET statement is flexible and has a variety of uses in SAS programming. These uses are determined by the options and statements that you use with the SET statement. They include • reading observations and variables from existing SAS data sets for further processing in the DATA step • concatenating and interleaving data sets, and performing one-to-one reading of data sets • Reading SAS data sets by using direct access methods. Data test; Set Sashelp.Air; Run; FIRSTOBS= The FIRSTOBS= option tells SAS at what line to begin reading data. Data test; Set Sashelp.air (firstobs = 10); Run; OBS= The OBS= option can be used anytime you want to read only a part of your data file. It tells SAS to stop reading when it gets to that line in the raw data file. Data test; Set Sashelp.air (obs = 10); Run; Data test; Set sashelp.class(firstobs =5 obs = 10); Run; In above example, work.test having 6 observations.