welcome to sas…session..!. what is sas..! a complete programming language with report formatting...

35
Welcome to SAS…Session..!

Upload: rosamund-bailey

Post on 24-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Welcome to

SAS…Session..!

Page 2: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

What is SAS..!

A Complete programming language with report formatting with statistical and mathematical capabilities.

Page 3: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

SAS Programming Structure

1st Part..

• The first part called the DATA step,

This part describes your input data

allows you to modify that data with arithmetic operations and logical decisions.

The DATA Step will format your data into a special file called SASdataset.

Page 4: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

2nd Part ..• The second part of SAS is a library of canned

routines called PROCEDURES.

The procedures can only use SAS datasets as input.

The Data step must always have preceded the Procedure section.

The procedures are executed by coding a special statement in SAS called a PROC statement

Page 5: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Functions of DATA Step.

• Reads raw data from input files.

• Selects records from input files.

• Writes out the SASdatasets.

Statements used in the DATA Step:

• DATA Statement.

DATA EMPFILE --Temporary File.

DATA UDEM.EMPFILE ---Permanent file

Page 6: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

• INFILE Statement :

INFILE (ddname) ---for Sequential

INFILE (ddname of PDS) (member name)

---for PDS

INFILE (ddname) VSAM ---for VSAM

Page 7: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

•INPUT Statement :

The INPUT statement describes the input data

record from the INFILE statement.

Standard record input : (fixed length)

INPUT variable [$] [startcolumn-endcolumn]

[.decimal]

DATA Empfile;

INPUT Empno 1-3 Name $ 4-19 Salary 20-26 .2

Page 8: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Non standard record input : (like Packed dec...)

INPUT @position Variable [$] Informat name

w.[d]

DATA Empfile;

INPUT @ Empcode 3. @Name $15.

:

RUN;

Page 9: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Informats type.

w. ---Standard numaric.

w.d ---Standard numeric with decimal

PDw.d ---Packed decimal.

COMMAw.d ---commas in numbers

Page 10: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

PROC Statement

• The PROC statement is used to invoke a SAS procedure

Procedure can-

• Read SAS dataset

• Compute statistics

• Print report

• Sequence SAS datasets.

Page 11: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Outputting Reports

Page 12: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

PROC PRINT

• Automatically formats a report from the current SAS dataset.

• Prints each detail record.

• Column headings default to the variable name but may be altered.

Page 13: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Syntax for to Print the default Report

DATA EMPFILE;

INFILE PERSON;

INPUT EmpNo $ 1-3 Name $ 4-19 DOB 20-26 Account 27-35;

PROC PRINT;

TITLE ‘EDS Employs List’;

RUN;

Page 14: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

REPORT

EDS Employs List

OBS EmpNo Name Account

1 100 AAAA XEROX

2 101 BBBB GM

3 102 CCCC XEROX

Page 15: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Using the SORT Procedure with PROC PRINT

PROC SORT;

BY ACCOUNT;

PROC PRINT DATA = EMPFILE;

TITLE ‘EDS Employs List’;

RUN;

Page 16: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

VAR Statement

• VAR Statement determines which variables will be printed in the report.

• Order of the variables in the VAR statement is the order the variables appear in the report.

PROC PRINT DATA=EMPFILE;

VAR ACCOUNT EMPNO NAME;

TITLE ‘EDS Employs List’;

RUN;

Page 17: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

ID Statement

• Suppresses printing the OBS column on the report.

• More than one variable can be listed in the ID statement.

PROC PRINT DATA=EMPFILE;

ID EMPNO;

TITLE ‘EDS Employs List’;

RUN;

Page 18: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Report

EDS Employs List

EmpNo Name Account

100 XXXX AAAA

101 YYYY BBBB

Page 19: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

SUM Statement

• The SUM Statement specifies which numeric variables will totaled.

PROC PRINT DATA=EMPFILE;

SUM SALARY;

TITLE ‘EDS Employs List’;

RUN;

Page 20: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Report

EDS Employs List

EmpNo Name Account Salary

101 AAAA XXXX 10000

102 BBBB YYYY 15000

======

250000

======

Page 21: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

BY Statement• This is just like Control Break in COBOL.• If BY Statements are present with SUM

Statement each BY group will also be totaled.

PROC PRINT ;

BY ACCOUNT;

SUM SALARY;

TITLE ‘EDS Employs List’;

RUN;

Page 22: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

EDS Employs List

EmpNo Name Account Salary

100 AAAA XXXX 10000

101 BBBB XXXX 10000

======

20000

======

200 CCCC YYYY 15000

201 DDDD YYYY 12000

======

27000

======

Page 23: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

LABLE & SPLIT Statements

• LABLE Statement is used to assign alternate column headers to variables.

• The SPLIT option on the PROC PRINT statement allows multiple line alternate column headings for the report.

• A SPLIT character is identified with the SPLIT option.When that character is used in the LABLE text causes the label to split into multiple lines at that point

Page 24: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Cont..• Any character may be used to split the line.

• The LABLE option on the PROC PRINT statement tells SAS to use the alternative label coded in the LABEL statement.

PROC PRINT LABEL/SPLIT=‘*’;

:

LABEL ACCOUNT=‘CLINT*NAME’;

Page 25: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

TITLE / FOOTNOTE Statements

• Lines from the top correspond to the number in the TITLE.

• Allows up to 10 title lines to be placed at the top of each page of the report.

• IF TITLE line within a group of titles is not coded it will result in a blank line

• FOOTNOTE is similar to TITLE Statement.

Page 26: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

PAGEBY Statement

• The PAGEBY variable is used with the BY Statement using the same variable. The page break occurs when the specified BY variable changes value .

PROC PRINT;

BY ACCOUNT;

PAGEBY ACCOUNT;

:

RUN;

Page 27: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

DATA Manipulations

Page 28: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

IF Statement

• Indicates which observations are included in the output SAS data set.

• When multiple logical expressions are used (with the AND and OR ) the ANDs are resolved first.

• Syntax:

IF var1 = var2 AND/OR var3 = var4;

Page 29: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

WHERE Statement

• Used to select observations from a SAS daaset.

• Operators for the WHERE statement include all operators of the IF statement

• Operators exclusively for WHERE:

WHERE Salary BETWEEN 15000 AND

20000 ;

Page 30: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Cont..

WHERE Name CONTAINS ‘SRINIVAS’;

------Searches for a character string

WHERE Name LIKE ‘S%’;

--selects name with the first character ‘S’

WHERE Account IN (‘GM’,’XEROX’);

Page 31: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

DO and END Statement• Execution of a DO statement specifies that

all statements between the DO and its matching END are to be executed.

DATA Empfile;

SET Personal;

IF ACCOUNT = ‘XEROX’

THEN DO;

NEWSAL= SALARY*1.2;

ELSE DO;

NEWSAL=SALARY;

END;

Page 32: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

DROP Statement

• The DROP is used to specify variables that are not included in the SASdatasets being created.

DATA Empfile1;

SET Personal;

WHERE ACCOUNT = ‘XEROX’;

DROP SALARY;

RUN;

Page 33: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

DELETE Statement

• This statement to tell SAS to stop processing the current observation.

DATA Empfile1;

SET Personal;

IF ACCOUNT = ‘XEROX’

THEN DELETE;

:

RUN;

Page 34: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

SAS System options

• The OPTION statement changes SAS system options.

• OPTION option1 option2..;

Some options:

DATE, NODATE --- Puts date on title page

CENTER, NOCENTER----Centers output

LS ---- Linesize for output 64-225

NUMBER, NONUMBER---Page numbering

Page 35: Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities

Thanks…!