SlideShare a Scribd company logo
SAS Basics   24 August 2007
An Overview of the SAS System
Objectives Understand the structure and design of the SAS System. Introduce the course scenario.
Components of the SAS System Base SAS Reporting  and  Graphics Analytical Visualization and Discovery Data Access and Management Business Solutions User Interfaces Application Development Web Enablement
The functionality of the SAS System is built around the four data-driven tasks common to virtually any application: 1. data access  2.  data management  3.  data analysis 4.  data presentation. Data-Driven Tasks
Turning Data into Information Process of delivering meaningful information: 80% data-related access scrub transform manage store and retrieve 20% analysis .
Turning Data into Information DATA Step SAS  Data  Sets Data PROC Steps Information
Design of the SAS System PC Workstation Servers / Midrange Mainframe Super Computer 90% independent 10% dependent MultiVendor Architecture
Design of the SAS System MultiEngine Architecture ™ DATA INGRES SYBASE INFORMIX ORACLE dBase Rdb DB2
In this course, you will be working with business data from International Airlines (IA). The various kinds of data IA maintains are flight data passenger data cargo data employee daa revenue data. Course Scenario
Some tasks you will be performing are: importing data  creating a list of employees producing a frequency table of  job codes summarizing data creating a report of salary information. Course Scenario
Chapter 2 Getting Started with the SAS System
Section 2.1 Introduction to SAS Programs
State the components of a SAS program. State the modes in which you can run a SAS program. Objectives
SAS Programs DATA steps are typically used to create SAS data sets. PROC steps are typically used to process SAS data sets (that is, generate reports and graphs, edit data, and sort data). A  SAS program  is a sequence of steps that the user submits for execution. Raw Data DATA Step Report SAS Data Set SAS Data Set PROC Step
SAS Programs data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run; DATA Step PROC Steps
Step Boundaries SAS steps begin with a DATA statement PROC statement. SAS detects the end of a step when it encounters a RUN statement (for most steps) a QUIT statement (for some procedures) the beginning of another step (DATA statement or PROC statement).
data  work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc  print data=work.staff; proc  means data=work.staff; class JobTitle; var Salary; run; Step Boundaries
Running a SAS Program You can invoke SAS in interactive windowing mode (SAS windowing environment) interactive menu-driven mode (Enterprise Guide, SAS/ASSIST, SAS/AF, or SAS/EIS software) batch mode noninteractive mode.
SAS Windowing Environment Interactive windows enable you to interface with SAS.
OS/390 (MVS) Batch Execution Place the JCL appropriate for your location before your SAS statements. //jobname JOB accounting info,name … // EXEC SAS //SYSIN DD * data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run;
Noninteractive Execution (Optional) To execute a SAS program in noninteractive mode,  use an editor to store the program in a file. (Directory-based users should use a filetype or extension of SAS.)  identify the file when you invoke SAS. Directory-based: OS/390 (TSO): SAS  filename SAS INPUT( filename )
Section 2.2 Running SAS Programs
Invoke the SAS System and include a SAS program into your session. Submit a program and browse the results. Navigate the SAS windowing environment. Objectives
Submitting a SAS Program When you execute a SAS program, the output generated by SAS is divided into two major parts: SAS log  contains information about the processing of    the SAS program, including any warning and    error messages. SAS output  contains reports generated by SAS    procedures and DATA steps.
SAS Log 1  data work.staff; 2  infile ' raw-data-file '; 3  input LastName $ 1-20 FirstName $ 21-30 4  JobTitle $ 36-43 Salary 54-59; 5  run; NOTE: The infile ' raw-data-file ' is: File Name= ' raw-data-file ', RECFM=V,LRECL=256 NOTE: 18 records were read from the infile ' raw-data-file '. The minimum record length was 59. The maximum record length was 59. NOTE: The data set WORK.STAFF has 18 observations and 4 variables. 6  proc print data=work.staff; 7  run; NOTE: There were 18 observations read from the dataset WORK.STAFF. 8  proc means data=work.staff; 9  class JobTitle; 10  var Salary; 11  run; NOTE: There were 18 observations read from the dataset WORK.STAFF.
PROC PRINT Output The SAS System First Obs  LastName  Name  JobTitle  Salary 1  TORRES  JAN  Pilot  50000 2  LANGKAMM  SARAH  Mechanic  80000 3  SMITH  MICHAEL  Mechanic  40000 4  LEISTNER  COLIN  Mechanic  36000 5  WADE  KIRSTEN  Pilot  85000 6  TOMAS  HARALD  Pilot  105000 7  WAUGH  TIM  Pilot  70000 8  LEHMANN  DAGMAR  Mechanic  64000 9  TRETTHAHN  MICHAEL  Pilot  100000 10  TIETZ  OTTO  Pilot  45000 11  O'DONOGHUE  ART  Mechanic  52000 12  WALKER  THOMAS  Pilot  95000 13  NOROVIITA  JOACHIM  Mechanic  78000 14  OESTERBERG  ANJA  Mechanic  80000 15  LAUFFER  CRAIG  Mechanic  40000 16  TORR  JUGDISH  Pilot  45000 17  WAGSCHAL  NADJA  Pilot  77500 18  TOERMOEN  JOCHEN  Pilot  65000
PROC MEANS Output The SAS System The MEANS Procedure Analysis Variable : Salary N JobTitle  Obs  N  Mean  Std Dev  Minimum ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Mechanic  8  8  58750.00  19151.65  36000.00 Pilot  10  10  73750.00  22523.14  45000.00 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Analysis Variable : Salary N JobTitle  Obs  Maximum ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Mechanic  8  80000.00 Pilot  10  105000.00 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Running a SAS Program c02s2d1.sas  userid .prog1.sascode(c02s2d1) This demonstration illustrates how to start a  SAS session, include and submit a SAS program,  and browse the results.
Exercises Include a SAS program. Submit the program and view the results.
Section 2.3 Mastering Fundamental Concepts
Define the components of a SAS data set. Define a SAS variable. Identify a missing value and a SAS date value. State the naming conventions for SAS data sets and variables. Explain SAS syntax rules. Investigate a SAS data set using the CONTENTS and PRINT procedures. Objectives
SAS Data Sets Data  Entry External File Conversion Process SAS  Data Set Descriptor Portion Data Portion Other Software Files
SAS Data Sets SAS data sets have a descriptor portion and a data portion. General data set information  * data set name  * data set label * date/time created  * storage information * number of observations Information for each variable * Name  * Type   * Length * Position * Format * Informat  * Label Descriptor Portion Data Portion
The  descriptor portion  of a SAS data set contains general information about the SAS data set (such as data set name and number of observations) variable attributes (name, type, length, position, informat, format, label). The  CONTENTS procedure  displays the descriptor portion of a SAS data set. Browsing the Descriptor Portion
General form of the CONTENTS procedure: Example: Browsing the Descriptor Portion PROC CONTENTS DATA= SAS-data-set ; RUN; proc contents data=work.staff; run; c02s3d1
Partial PROC CONTENTS Output The SAS System The CONTENTS Procedure Data Set Name: WORK.STAFF  Observations:  18 Member Type:  DATA  Variables:  4 Engine:  V8  Indexes:  0 Created:  18:09 Sunday,  Observation Length:  48 July 22, 2001 Last Modified: 18:09 Sunday,  Deleted Observations: 0 July 22, 2001 Protection:  Compressed:  NO Data Set Type:  Sorted:  NO Label: -----Alphabetic List of Variables and Attributes----- #  Variable  Type  Len  Pos ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 2  FirstName  Char  10  28 3  JobTitle  Char  8  38 1  LastName  Char  20  8 4  Salary  Num  8  0
SAS Data Sets: Data Portion Numeric  values Variable names Variable values LastName  FirstName  JobTitle  Salary TORRES  JAN  Pilot  50000 LANGKAMM  SARAH  Mechanic  80000 SMITH  MICHAEL  Mechanic  40000 WAGSCHAL  NADJA  Pilot  77500 TOERMOEN  JOCHEN  Pilot  65000 The  data portion   of a SAS data set is a rectangular table of character and/or numeric data values. Character values
SAS Variable Values There are two types of variables: character contain any value: letters, numbers, special characters, and blanks. Character values are stored with a length of  1 to 32,767 bytes . One byte equals one character. numeric stored as floating point numbers in  8 bytes   of storage by default. Eight bytes of floating point storage provide space for 16 or 17 significant digits. You are not restricted to  8 digits.
SAS names  can be 32 characters long. can be uppercase, lowercase, or mixed-case. must start with a letter or underscore. Subsequent characters can be letters, underscores, or numeric digits. SAS Data Set and Variable Names
Select the default valid SAS names. Valid SAS Names  data5mon  5monthsdata  five months data    fivemonthsdata  data#5
Select the default valid SAS names. Valid SAS Names    fivemonthsdata  data5mon  data5mon    5monthsdata    five months data    fivemonthsdata    data#5
SAS stores  date   values as numeric values. A  SAS date value  is stored as the number of days between January 1, 1960, and a specific date. SAS Date Values 01JAN1959 01JAN1960 01JAN1961 store -365 0 366 display 01/01/1959 01/01/1960 01/01/1961
Missing Data Values LastName  FirstName  JobTitle  Salary TORRES  JAN  Pilot  50000 LANGKAMM  SARAH  Mechanic  80000 SMITH  MICHAEL  Mechanic  . WAGSCHAL  NADJA  Pilot  77500 TOERMOEN  JOCHEN  65000 A value must exist for every variable for each observation. Missing values are valid values. A numeric missing value is displayed as a period. A character missing value is displayed as a blank.
The PRINT procedure displays the data portion of a  SAS data set. By default, PROC PRINT displays all observations all variables an Obs column on the left side. Browsing the Data Portion
General form of the PRINT procedure: Example: Browsing the Data Portion PROC PRINT DATA= SAS-data-set ; RUN; proc print data=work.staff; run; c02s3d1
PROC PRINT Output The SAS System First Obs  LastName  Name  JobTitle  Salary 1  TORRES  JAN  Pilot  50000 2  LANGKAMM  SARAH  Mechanic  80000 3  SMITH  MICHAEL  Mechanic  40000 4  LEISTNER  COLIN  Mechanic  36000 5  WADE  KIRSTEN  Pilot  85000 6  TOMAS  HARALD  Pilot  105000 7  WAUGH  TIM  Pilot  70000 8  LEHMANN  DAGMAR  Mechanic  64000 9  TRETTHAHN  MICHAEL  Pilot  100000 10  TIETZ  OTTO  Pilot  45000 11  O'DONOGHUE  ART  Mechanic  52000 12  WALKER  THOMAS  Pilot  95000 13  NOROVIITA  JOACHIM  Mechanic  78000 14  OESTERBERG  ANJA  Mechanic  80000 15  LAUFFER  CRAIG  Mechanic  40000 16  TORR  JUGDISH  Pilot  45000 17  WAGSCHAL  NADJA  Pilot  77500 18  TOERMOEN  JOCHEN  Pilot  65000
SAS Data Set Terminology SAS documentation and text in the SAS windowing environment use the following terms interchangeably: SAS Data Set SAS Table Variable Column Observation Row
SAS statements usually begin with an  identifying keyword always end with a  semicolon . data  work.staff ; infile  ' raw-data-file ' ; input  LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59 ; run ; proc  print data=work.staff ; run ; proc  means data=work.staff ; class  JobTitle ; var  Salary ; run ; SAS Syntax Rules
SAS Syntax Rules SAS statements are free-format. One or more blanks or special characters can be used to separate words. They can begin and end in any column. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing ... data  work . staff ;   infile  ' raw-data-file ' ; input  LastName $ 1 - 20 FirstName $ 21 - 30 JobTitle $ 36 - 43 Salary 54 - 59 ; run ; proc   means data=work . staff ;  class  JobTitle ;   var  Salary ; run ;
SAS Syntax Rules ... ... SAS statements are free-format. One or more blanks or special characters can be used to separate words. They can begin and end in any column. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing data  work . staff ;   infile  ' raw-data-file ' ; input  LastName $ 1 - 20 FirstName $ 21 - 30 JobTitle $ 36 - 43 Salary 54 - 59 ; run ; proc   means data=work . staff ;  class  JobTitle ;   var  Salary ; run ;
SAS Syntax Rules data work.staff;  infile 'raw-data-file'; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff;  class JobTitle;  var Salary;run; SAS statements are free-format. One or more blanks or special characters can be used to separate words. They can begin and end in any column. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing
SAS Syntax Rules SAS statements are free-format. One or more blanks or special characters can be used to separate words . They can begin and end in any column. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing ... data  work . staff ;   infile  ' raw-data-file ' ; input  LastName $ 1 - 20 FirstName $ 21 - 30 JobTitle $ 36 - 43 Salary 54 - 59 ; run ; proc   means data=work . staff ;  class  JobTitle ;   var  Salary ; run ;
SAS Syntax Rules data work.staff;  infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff;  class JobTitle;  var Salary;run; ... SAS statements are free-format. One or more blanks or special characters can be used to separate words. They can begin and end in any column. A singlestatement can span multiple lines. Several statements can be on the same line. Unconventional Spacing
SAS Syntax Rules ... ... data work.staff;  infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff;  class JobTitle;  var Salary;run; SAS statements are free-format. They can begin and end in any column. One or more blanks or special characters can be used to separate words. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing
Good spacing makes the program easier to read. Conventional Spacing data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTaitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run; SAS Syntax Rules
Type  /* to begin  a comment. Type your  comment text . Type  */ to end  the comment. /*   Create work.staff data set   */ data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; /*   Produce listing report of work.staff   */ proc print data=work.staff; run; c02s3d2 SAS Comments
This exercise reinforces the concepts discussed previously. Exercises
Section 2.4 Diagnosing and Correcting Syntax Errors
Identify SAS syntax errors. Debug and edit a program with errors. Resubmit the corrected program. Save the corrected program. Objectives
Syntax Errors daat work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff  run; proc means data=work.staff average max; class JobTitle; var Salary; run; Syntax errors include misspelled keywords  missing or invalid punctuation invalid options.
Debugging a SAS Program  c02s4d1.sas  userid .prog1.sascode(c02s4d1) c02s4d2.sas userid .prog1.sascode(c02s4d2) This demonstration illustrates how to submit a  SAS program that contains errors, diagnose the errors, correct the errors, and save the corrected program.
Recall a Submitted Program daat work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff  run; proc means data=work.staff average max; class JobTitle; var Salary; run; data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff;  run; proc means data=work.staff mean max; class Jobtitle; var Salary; run; Program statements accumulate in a recall buffer each time you issue a SUBMIT command. Submit Number 1 Submit Number 2
Recall a Submitted Program Submit Number 1 Submit Number 2 Issue RECALL once. Submit number 2 statements are recalled. Issue the RECALL command once to recall the most recently submitted program. data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff;  run; proc means data=work.staff mean max; class JobTitle; var Salary; run;
Recall a Submitted Program Submit Number 1 Submit Number 2 daat work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff  run; proc means data=work.staff average max; class JobTitle; var Salary; run; data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff;  run; proc means data=work.staff mean max; class JobTitle; var Salary; run; Issue RECALL again. Issue the RECALL command again to recall submit number 1 statements.
Review: Save Your Program Use the FILE command with the appropriate file naming convention for your operating environment. OS/390:  UNIX: Windows: FILE  ' userid.prog1 .sascode( myprog )' FILE  '/users/prog1/ myprog .sas' FILE  'c:\workshop\winsas\prog1\ myprog .sas'
Exercises Debug a program that contains errors.
Section 2.5 Exploring Your SAS Environment (Self-Study)

More Related Content

PPT
INTRODUCTION TO SAS
PDF
SAS cheat sheet
PPT
SAS BASICS
PPTX
SAS Mainframe -Program-Tips
PPTX
Proc SQL in SAS Enterprise Guide 4.3
PPT
Base SAS Statistics Procedures
PDF
Base SAS Full Sample Paper
INTRODUCTION TO SAS
SAS cheat sheet
SAS BASICS
SAS Mainframe -Program-Tips
Proc SQL in SAS Enterprise Guide 4.3
Base SAS Statistics Procedures
Base SAS Full Sample Paper

What's hot (20)

DOCX
Learn SAS Programming
PPT
SAS Macros
PPT
Basics Of SAS Programming Language
DOCX
Base sas interview questions
PPT
Understanding SAS Data Step Processing
PDF
Introduction To Sas
PPT
Utility Procedures in SAS
PPT
Data Match Merging in SAS
PPT
Hechsp 001 Chapter 2
PDF
Introduction to SAS
DOC
Introduction to SAS
PPT
SAS ODS HTML
PPTX
SAS basics Step by step learning
PDF
Introduction to SAS Data Set Options
PDF
SAS Internal Training
PPTX
Salesforce Summer 14 Release
PPTX
Understanding sas data step processing.
PDF
Sas Talk To R Users Group
PDF
A Step-By-Step Introduction to SAS Report Procedure
Learn SAS Programming
SAS Macros
Basics Of SAS Programming Language
Base sas interview questions
Understanding SAS Data Step Processing
Introduction To Sas
Utility Procedures in SAS
Data Match Merging in SAS
Hechsp 001 Chapter 2
Introduction to SAS
Introduction to SAS
SAS ODS HTML
SAS basics Step by step learning
Introduction to SAS Data Set Options
SAS Internal Training
Salesforce Summer 14 Release
Understanding sas data step processing.
Sas Talk To R Users Group
A Step-By-Step Introduction to SAS Report Procedure
Ad

Similar to Prog1 chap1 and chap 2 (20)

PPT
BASE SAS Training presentation of coding
PDF
I need help with Applied Statistics and the SAS Programming Language.pdf
PPT
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
PPT
Sas classes in mumbai
DOCX
SAS Programming Notes
PPT
SAS - overview of SAS
PDF
Sas summary guide
PPTX
Introducción al Software Analítico SAS
PDF
Introduction to sas
PDF
Analytics with SAS
PPT
Sas short course_presentation_11-4-09
PPT
Sas short course_presentation_11-4-09
PDF
Sas cheat
PDF
Sas language reference concepts
PPT
8323 Stats - Lesson 1 - 03 Introduction To Sas 2008
PDF
Introduction to-sas-1211594349119006-8
PPT
Sas-training-in-mumbai
PPTX
LWPG1_001 Chapter 4.pptx
PPT
Reading Fixed And Varying Data
DOCX
Sample Questions The following sample questions are not in.docx
BASE SAS Training presentation of coding
I need help with Applied Statistics and the SAS Programming Language.pdf
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
Sas classes in mumbai
SAS Programming Notes
SAS - overview of SAS
Sas summary guide
Introducción al Software Analítico SAS
Introduction to sas
Analytics with SAS
Sas short course_presentation_11-4-09
Sas short course_presentation_11-4-09
Sas cheat
Sas language reference concepts
8323 Stats - Lesson 1 - 03 Introduction To Sas 2008
Introduction to-sas-1211594349119006-8
Sas-training-in-mumbai
LWPG1_001 Chapter 4.pptx
Reading Fixed And Varying Data
Sample Questions The following sample questions are not in.docx
Ad

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Basic Mud Logging Guide for educational purpose
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Sports Quiz easy sports quiz sports quiz
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Insiders guide to clinical Medicine.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Abdominal Access Techniques with Prof. Dr. R K Mishra
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
RMMM.pdf make it easy to upload and study
Basic Mud Logging Guide for educational purpose
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Sports Quiz easy sports quiz sports quiz
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
2.FourierTransform-ShortQuestionswithAnswers.pdf
VCE English Exam - Section C Student Revision Booklet
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Insiders guide to clinical Medicine.pdf

Prog1 chap1 and chap 2

  • 1. SAS Basics 24 August 2007
  • 2. An Overview of the SAS System
  • 3. Objectives Understand the structure and design of the SAS System. Introduce the course scenario.
  • 4. Components of the SAS System Base SAS Reporting and Graphics Analytical Visualization and Discovery Data Access and Management Business Solutions User Interfaces Application Development Web Enablement
  • 5. The functionality of the SAS System is built around the four data-driven tasks common to virtually any application: 1. data access 2. data management 3. data analysis 4. data presentation. Data-Driven Tasks
  • 6. Turning Data into Information Process of delivering meaningful information: 80% data-related access scrub transform manage store and retrieve 20% analysis .
  • 7. Turning Data into Information DATA Step SAS Data Sets Data PROC Steps Information
  • 8. Design of the SAS System PC Workstation Servers / Midrange Mainframe Super Computer 90% independent 10% dependent MultiVendor Architecture
  • 9. Design of the SAS System MultiEngine Architecture ™ DATA INGRES SYBASE INFORMIX ORACLE dBase Rdb DB2
  • 10. In this course, you will be working with business data from International Airlines (IA). The various kinds of data IA maintains are flight data passenger data cargo data employee daa revenue data. Course Scenario
  • 11. Some tasks you will be performing are: importing data creating a list of employees producing a frequency table of job codes summarizing data creating a report of salary information. Course Scenario
  • 12. Chapter 2 Getting Started with the SAS System
  • 13. Section 2.1 Introduction to SAS Programs
  • 14. State the components of a SAS program. State the modes in which you can run a SAS program. Objectives
  • 15. SAS Programs DATA steps are typically used to create SAS data sets. PROC steps are typically used to process SAS data sets (that is, generate reports and graphs, edit data, and sort data). A SAS program is a sequence of steps that the user submits for execution. Raw Data DATA Step Report SAS Data Set SAS Data Set PROC Step
  • 16. SAS Programs data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run; DATA Step PROC Steps
  • 17. Step Boundaries SAS steps begin with a DATA statement PROC statement. SAS detects the end of a step when it encounters a RUN statement (for most steps) a QUIT statement (for some procedures) the beginning of another step (DATA statement or PROC statement).
  • 18. data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; proc means data=work.staff; class JobTitle; var Salary; run; Step Boundaries
  • 19. Running a SAS Program You can invoke SAS in interactive windowing mode (SAS windowing environment) interactive menu-driven mode (Enterprise Guide, SAS/ASSIST, SAS/AF, or SAS/EIS software) batch mode noninteractive mode.
  • 20. SAS Windowing Environment Interactive windows enable you to interface with SAS.
  • 21. OS/390 (MVS) Batch Execution Place the JCL appropriate for your location before your SAS statements. //jobname JOB accounting info,name … // EXEC SAS //SYSIN DD * data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run;
  • 22. Noninteractive Execution (Optional) To execute a SAS program in noninteractive mode, use an editor to store the program in a file. (Directory-based users should use a filetype or extension of SAS.) identify the file when you invoke SAS. Directory-based: OS/390 (TSO): SAS filename SAS INPUT( filename )
  • 23. Section 2.2 Running SAS Programs
  • 24. Invoke the SAS System and include a SAS program into your session. Submit a program and browse the results. Navigate the SAS windowing environment. Objectives
  • 25. Submitting a SAS Program When you execute a SAS program, the output generated by SAS is divided into two major parts: SAS log contains information about the processing of the SAS program, including any warning and error messages. SAS output contains reports generated by SAS procedures and DATA steps.
  • 26. SAS Log 1 data work.staff; 2 infile ' raw-data-file '; 3 input LastName $ 1-20 FirstName $ 21-30 4 JobTitle $ 36-43 Salary 54-59; 5 run; NOTE: The infile ' raw-data-file ' is: File Name= ' raw-data-file ', RECFM=V,LRECL=256 NOTE: 18 records were read from the infile ' raw-data-file '. The minimum record length was 59. The maximum record length was 59. NOTE: The data set WORK.STAFF has 18 observations and 4 variables. 6 proc print data=work.staff; 7 run; NOTE: There were 18 observations read from the dataset WORK.STAFF. 8 proc means data=work.staff; 9 class JobTitle; 10 var Salary; 11 run; NOTE: There were 18 observations read from the dataset WORK.STAFF.
  • 27. PROC PRINT Output The SAS System First Obs LastName Name JobTitle Salary 1 TORRES JAN Pilot 50000 2 LANGKAMM SARAH Mechanic 80000 3 SMITH MICHAEL Mechanic 40000 4 LEISTNER COLIN Mechanic 36000 5 WADE KIRSTEN Pilot 85000 6 TOMAS HARALD Pilot 105000 7 WAUGH TIM Pilot 70000 8 LEHMANN DAGMAR Mechanic 64000 9 TRETTHAHN MICHAEL Pilot 100000 10 TIETZ OTTO Pilot 45000 11 O'DONOGHUE ART Mechanic 52000 12 WALKER THOMAS Pilot 95000 13 NOROVIITA JOACHIM Mechanic 78000 14 OESTERBERG ANJA Mechanic 80000 15 LAUFFER CRAIG Mechanic 40000 16 TORR JUGDISH Pilot 45000 17 WAGSCHAL NADJA Pilot 77500 18 TOERMOEN JOCHEN Pilot 65000
  • 28. PROC MEANS Output The SAS System The MEANS Procedure Analysis Variable : Salary N JobTitle Obs N Mean Std Dev Minimum ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Mechanic 8 8 58750.00 19151.65 36000.00 Pilot 10 10 73750.00 22523.14 45000.00 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Analysis Variable : Salary N JobTitle Obs Maximum ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ Mechanic 8 80000.00 Pilot 10 105000.00 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  • 29. Running a SAS Program c02s2d1.sas userid .prog1.sascode(c02s2d1) This demonstration illustrates how to start a SAS session, include and submit a SAS program, and browse the results.
  • 30. Exercises Include a SAS program. Submit the program and view the results.
  • 31. Section 2.3 Mastering Fundamental Concepts
  • 32. Define the components of a SAS data set. Define a SAS variable. Identify a missing value and a SAS date value. State the naming conventions for SAS data sets and variables. Explain SAS syntax rules. Investigate a SAS data set using the CONTENTS and PRINT procedures. Objectives
  • 33. SAS Data Sets Data Entry External File Conversion Process SAS Data Set Descriptor Portion Data Portion Other Software Files
  • 34. SAS Data Sets SAS data sets have a descriptor portion and a data portion. General data set information * data set name * data set label * date/time created * storage information * number of observations Information for each variable * Name * Type * Length * Position * Format * Informat * Label Descriptor Portion Data Portion
  • 35. The descriptor portion of a SAS data set contains general information about the SAS data set (such as data set name and number of observations) variable attributes (name, type, length, position, informat, format, label). The CONTENTS procedure displays the descriptor portion of a SAS data set. Browsing the Descriptor Portion
  • 36. General form of the CONTENTS procedure: Example: Browsing the Descriptor Portion PROC CONTENTS DATA= SAS-data-set ; RUN; proc contents data=work.staff; run; c02s3d1
  • 37. Partial PROC CONTENTS Output The SAS System The CONTENTS Procedure Data Set Name: WORK.STAFF Observations: 18 Member Type: DATA Variables: 4 Engine: V8 Indexes: 0 Created: 18:09 Sunday, Observation Length: 48 July 22, 2001 Last Modified: 18:09 Sunday, Deleted Observations: 0 July 22, 2001 Protection: Compressed: NO Data Set Type: Sorted: NO Label: -----Alphabetic List of Variables and Attributes----- # Variable Type Len Pos ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 2 FirstName Char 10 28 3 JobTitle Char 8 38 1 LastName Char 20 8 4 Salary Num 8 0
  • 38. SAS Data Sets: Data Portion Numeric values Variable names Variable values LastName FirstName JobTitle Salary TORRES JAN Pilot 50000 LANGKAMM SARAH Mechanic 80000 SMITH MICHAEL Mechanic 40000 WAGSCHAL NADJA Pilot 77500 TOERMOEN JOCHEN Pilot 65000 The data portion of a SAS data set is a rectangular table of character and/or numeric data values. Character values
  • 39. SAS Variable Values There are two types of variables: character contain any value: letters, numbers, special characters, and blanks. Character values are stored with a length of 1 to 32,767 bytes . One byte equals one character. numeric stored as floating point numbers in 8 bytes of storage by default. Eight bytes of floating point storage provide space for 16 or 17 significant digits. You are not restricted to 8 digits.
  • 40. SAS names can be 32 characters long. can be uppercase, lowercase, or mixed-case. must start with a letter or underscore. Subsequent characters can be letters, underscores, or numeric digits. SAS Data Set and Variable Names
  • 41. Select the default valid SAS names. Valid SAS Names  data5mon  5monthsdata  five months data  fivemonthsdata  data#5
  • 42. Select the default valid SAS names. Valid SAS Names  fivemonthsdata  data5mon  data5mon  5monthsdata  five months data  fivemonthsdata  data#5
  • 43. SAS stores date values as numeric values. A SAS date value is stored as the number of days between January 1, 1960, and a specific date. SAS Date Values 01JAN1959 01JAN1960 01JAN1961 store -365 0 366 display 01/01/1959 01/01/1960 01/01/1961
  • 44. Missing Data Values LastName FirstName JobTitle Salary TORRES JAN Pilot 50000 LANGKAMM SARAH Mechanic 80000 SMITH MICHAEL Mechanic . WAGSCHAL NADJA Pilot 77500 TOERMOEN JOCHEN 65000 A value must exist for every variable for each observation. Missing values are valid values. A numeric missing value is displayed as a period. A character missing value is displayed as a blank.
  • 45. The PRINT procedure displays the data portion of a SAS data set. By default, PROC PRINT displays all observations all variables an Obs column on the left side. Browsing the Data Portion
  • 46. General form of the PRINT procedure: Example: Browsing the Data Portion PROC PRINT DATA= SAS-data-set ; RUN; proc print data=work.staff; run; c02s3d1
  • 47. PROC PRINT Output The SAS System First Obs LastName Name JobTitle Salary 1 TORRES JAN Pilot 50000 2 LANGKAMM SARAH Mechanic 80000 3 SMITH MICHAEL Mechanic 40000 4 LEISTNER COLIN Mechanic 36000 5 WADE KIRSTEN Pilot 85000 6 TOMAS HARALD Pilot 105000 7 WAUGH TIM Pilot 70000 8 LEHMANN DAGMAR Mechanic 64000 9 TRETTHAHN MICHAEL Pilot 100000 10 TIETZ OTTO Pilot 45000 11 O'DONOGHUE ART Mechanic 52000 12 WALKER THOMAS Pilot 95000 13 NOROVIITA JOACHIM Mechanic 78000 14 OESTERBERG ANJA Mechanic 80000 15 LAUFFER CRAIG Mechanic 40000 16 TORR JUGDISH Pilot 45000 17 WAGSCHAL NADJA Pilot 77500 18 TOERMOEN JOCHEN Pilot 65000
  • 48. SAS Data Set Terminology SAS documentation and text in the SAS windowing environment use the following terms interchangeably: SAS Data Set SAS Table Variable Column Observation Row
  • 49. SAS statements usually begin with an identifying keyword always end with a semicolon . data work.staff ; infile ' raw-data-file ' ; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59 ; run ; proc print data=work.staff ; run ; proc means data=work.staff ; class JobTitle ; var Salary ; run ; SAS Syntax Rules
  • 50. SAS Syntax Rules SAS statements are free-format. One or more blanks or special characters can be used to separate words. They can begin and end in any column. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing ... data work . staff ; infile ' raw-data-file ' ; input LastName $ 1 - 20 FirstName $ 21 - 30 JobTitle $ 36 - 43 Salary 54 - 59 ; run ; proc means data=work . staff ; class JobTitle ; var Salary ; run ;
  • 51. SAS Syntax Rules ... ... SAS statements are free-format. One or more blanks or special characters can be used to separate words. They can begin and end in any column. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing data work . staff ; infile ' raw-data-file ' ; input LastName $ 1 - 20 FirstName $ 21 - 30 JobTitle $ 36 - 43 Salary 54 - 59 ; run ; proc means data=work . staff ; class JobTitle ; var Salary ; run ;
  • 52. SAS Syntax Rules data work.staff; infile 'raw-data-file'; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff; class JobTitle; var Salary;run; SAS statements are free-format. One or more blanks or special characters can be used to separate words. They can begin and end in any column. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing
  • 53. SAS Syntax Rules SAS statements are free-format. One or more blanks or special characters can be used to separate words . They can begin and end in any column. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing ... data work . staff ; infile ' raw-data-file ' ; input LastName $ 1 - 20 FirstName $ 21 - 30 JobTitle $ 36 - 43 Salary 54 - 59 ; run ; proc means data=work . staff ; class JobTitle ; var Salary ; run ;
  • 54. SAS Syntax Rules data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff; class JobTitle; var Salary;run; ... SAS statements are free-format. One or more blanks or special characters can be used to separate words. They can begin and end in any column. A singlestatement can span multiple lines. Several statements can be on the same line. Unconventional Spacing
  • 55. SAS Syntax Rules ... ... data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc means data=work.staff; class JobTitle; var Salary;run; SAS statements are free-format. They can begin and end in any column. One or more blanks or special characters can be used to separate words. A single statement can span multiple lines. Several statements can be on the same line. Unconventional Spacing
  • 56. Good spacing makes the program easier to read. Conventional Spacing data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTaitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff; class JobTitle; var Salary; run; SAS Syntax Rules
  • 57. Type /* to begin a comment. Type your comment text . Type */ to end the comment. /* Create work.staff data set */ data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; /* Produce listing report of work.staff */ proc print data=work.staff; run; c02s3d2 SAS Comments
  • 58. This exercise reinforces the concepts discussed previously. Exercises
  • 59. Section 2.4 Diagnosing and Correcting Syntax Errors
  • 60. Identify SAS syntax errors. Debug and edit a program with errors. Resubmit the corrected program. Save the corrected program. Objectives
  • 61. Syntax Errors daat work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff run; proc means data=work.staff average max; class JobTitle; var Salary; run; Syntax errors include misspelled keywords missing or invalid punctuation invalid options.
  • 62. Debugging a SAS Program c02s4d1.sas userid .prog1.sascode(c02s4d1) c02s4d2.sas userid .prog1.sascode(c02s4d2) This demonstration illustrates how to submit a SAS program that contains errors, diagnose the errors, correct the errors, and save the corrected program.
  • 63. Recall a Submitted Program daat work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff run; proc means data=work.staff average max; class JobTitle; var Salary; run; data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff mean max; class Jobtitle; var Salary; run; Program statements accumulate in a recall buffer each time you issue a SUBMIT command. Submit Number 1 Submit Number 2
  • 64. Recall a Submitted Program Submit Number 1 Submit Number 2 Issue RECALL once. Submit number 2 statements are recalled. Issue the RECALL command once to recall the most recently submitted program. data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff mean max; class JobTitle; var Salary; run;
  • 65. Recall a Submitted Program Submit Number 1 Submit Number 2 daat work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff run; proc means data=work.staff average max; class JobTitle; var Salary; run; data work.staff; infile ' raw-data-file '; input LastName $ 1-20 FirstName $ 21-30 JobTitle $ 36-43 Salary 54-59; run; proc print data=work.staff; run; proc means data=work.staff mean max; class JobTitle; var Salary; run; Issue RECALL again. Issue the RECALL command again to recall submit number 1 statements.
  • 66. Review: Save Your Program Use the FILE command with the appropriate file naming convention for your operating environment. OS/390: UNIX: Windows: FILE ' userid.prog1 .sascode( myprog )' FILE '/users/prog1/ myprog .sas' FILE 'c:\workshop\winsas\prog1\ myprog .sas'
  • 67. Exercises Debug a program that contains errors.
  • 68. Section 2.5 Exploring Your SAS Environment (Self-Study)

Editor's Notes

  • #47: When there are too many columns to fit on one line, they are split into multiple lines by PROC PRINT.