Presentation is loading. Please wait.

Presentation is loading. Please wait.

SAS Programming Introduction to SAS.

Similar presentations


Presentation on theme: "SAS Programming Introduction to SAS."— Presentation transcript:

1 SAS Programming Introduction to SAS

2 Instructor Sam Lam Programming Consultant / Instructor
Website:

3 Today’s Topic Concepts: SAS Overview SAS Windows Data set and Library
Data Step Programming: Creating a SAS data set INPUT and DATALINES SET statement Creating a Permanent Library Saving a SAS data set Functions Sum Mean, Min, Max Substr Index, Indexc And more …

4 SAS Overview

5 What is SAS? SAS stands for Statistical Analysis System (Software)
Started in 1966 in University of North Carolina Currently used in more than 15 industries such as life science, marketing, finance, government, hotel, manufacturing ...etc.

6 What does SAS do? SAS is used to turn raw data into information where business decision can be made!

7 What does SAS do? Example 1: Data Mining
Businesses make better marketing decision by extracting extra consumer insights from data using SAS

8 What does SAS do? Example 2: Life Science
Pharmaceutical companies analyze the effectiveness of the newly developed clinical treatment using SAS

9 What does SAS do? Example 3: Fraud Detection
Financial institutes develop the fraud detection system using SAS

10 Major Competitions R SPSS

11 SAS Components There are many individual components in SAS: SAS Base
SAS/STAT SAS/GRAPH Mining Enterprise

12 SAS Basics

13 3 SAS Windows Editor Window Log Window Output Window

14 Editor Window The window where coding takes place
Click the “running man” icon to compile the program Highlight the code to run only the highlighted part of the program F3 = short cut in running the code

15 Log Window The window showing the programming status (errors) when compiled Error message (in red) and Warning message (in green) should be cleaned up

16 Output Window The window where statistical results are displayed.

17 SAS Data set

18 SAS Data set Data set is the file where data is being stored
Contains variable (column) and observation (row) Temporary vs. Permanent data set

19 SAS Data set Characteristics:
Data cannot be modified without coding (unlike Excel spreadsheet) Proc Contents shows the descriptor portion of the data set

20 Data Portion vs. Descriptor Portion
Data portion shows the actual contents of the data set such as variables and observations Descriptor portion shows the details of the data set such as the data set size, # of observations and list of variables.

21 Proc Contents Example Proc Contents Data=Test; Run;

22 SAS Variable

23 SAS Variable There are 6 attributes that define each variables: Name, Label, Length, Type, Format and Informat

24 Data Step

25 What is Data Step? Data Step is the basic programming unit of SAS.
It is used to create data sets in SAS.

26 Basic Data Step Characteristics
It starts with Data and ends with Run. Every complete line of code ends with a semi-colon. Data Step Structure: Data {name}; {coding}; Run;

27 Data Step Example Data Example; a = 1; Run;

28 Programming Tips 1. SAS is not sensitive to case
2. SAS is not sensitive to indentation

29 Creating a Data set

30 1. INPUT and DATALINES statements
Example: Data Test; INPUT a b; DATALINES; 1 2 1 3 ; run;

31 1. INPUT and DATALINES statements
Note: (1) The syntax INPUT is used to specify the variables to be created. In our example, variable a and variable b are created. (2) The syntax DATALINES specifies where the data should be read in.

32 Exercise 1 Create a new called Report. This data set should have 3 variables: Student, Gender and Results. The 3 variables should contain the following data: John M 90 Mary F 97 Peter M 77

33 2. SET Statement Example Data Report2; SET Report; Run;

34 2. SET Statement Example 2 Data Report2; SET Report; IF Gender = “M”;
Run;

35 2. SET Statement Example 3 Data Report2; SET Report;
IF Result >=90; Run;

36 3. SET Statement Example 4 Data Report2; SET Report;
KEEP Student Results; Run;

37 SAS Library

38 Library is the folder containing the SAS data sets.
SAS Library Library is the folder containing the SAS data sets. SAS dataset MUST be placed in a SAS library before being used in SAS.

39 SAS Library There are two types of library:
Work Library vs. Permanent Library

40 Work Library Work library contains working datasets
Datasets from the Work library will be deleted once the system is terminated

41 Accessing Permanent Library

42 Accessing Permanent Library
In order to access the data sets from the permanent library, you need to use library reference. Example Data Cars; Set SASHelp.Cars; Run;

43 Library Reference Set SASHelp.Cars;
The library reference allows you to refer to the data set from the correct library. SASHelp.Cars = The Cars data set from the SASHelp library Work.Cars = The Cars data set from the Work library.

44 Library Reference = Important note:
The library reference is not needed when refering to a data set from the WORK library. Data Work.Car; Car = 10; Run; Data Cars; Car = 10; Run; =

45 Accessing Existing Data Sets

46 Creating a Permanent library
Libname Statement: LIBNAME RyerSAS “c:\path";

47 Creating a Permanent library
LIBNAME RyerSAS “c:\path”; LIBNAME: The syntax creating the library in SAS RyerSAS: The name of the library created “c:\path": The path to the Windows directory.

48 Creating a Permanent library
Step 2: Check the Log window to see if there is any error or warning message.

49 Creating a Permanent library
If everything is fine, there should be a new library created!

50 Exercise Download the zip file from the link below:
Save the data sets into the Windows directory.

51 Exercise 2 Copy the ForestFire data set into the WORK library.

52 Programming Tips It is a good programming practice to copy the data set into the WORK library before modifying the data. The permanent library saves the “source” data. You do not want to modify it.

53 Saving the dataset into a Windows directory

54 Saving a dataset LIBNAME RyerSAS “c:\path"; Data RyerSAS.FIRE2;
Set FirestFore; Run;

55 Note: (1) In order to put the data set into the RyerSAS library (instead of the Work library), we have to add the library reference before the dataset name. RyerSAS is the library reference in our example.

56 Note: (2) The SET function copies the content from the ForestFire dataset into the RyerSAS.FIRE2 dataset.


Download ppt "SAS Programming Introduction to SAS."

Similar presentations


Ads by Google