350 likes | 469 Views
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
E N D
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.
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
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
INFILE Statement : INFILE (ddname) ---for Sequential INFILE (ddname of PDS) (member name) ---for PDS INFILE (ddname) VSAM ---for VSAM
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
Non standard record input : (like Packed dec...) INPUT @position Variable [$] Informat name w.[d] DATA Empfile; INPUT @ Empcode 3. @Name $15. : RUN;
Informats type. w. ---Standard numaric. w.d ---Standard numeric with decimal PDw.d ---Packed decimal. COMMAw.d ---commas in numbers
PROC Statement • The PROC statement is used to invoke a SAS procedure Procedure can- • Read SAS dataset • Compute statistics • Print report • Sequence SAS datasets.
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.
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;
REPORT EDS Employs List OBS EmpNo Name Account 1 100 AAAA XEROX 2 101 BBBB GM 3 102 CCCC XEROX
Using the SORT Procedure with PROC PRINT PROC SORT; BY ACCOUNT; PROC PRINT DATA = EMPFILE; TITLE ‘EDS Employs List’; RUN;
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;
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;
Report EDS Employs List EmpNo Name Account 100 XXXX AAAA 101 YYYY BBBB
SUM Statement • The SUM Statement specifies which numeric variables will totaled. PROC PRINT DATA=EMPFILE; SUM SALARY; TITLE ‘EDS Employs List’; RUN;
Report EDS Employs List EmpNo Name Account Salary 101 AAAA XXXX 10000 102 BBBB YYYY 15000 ====== 250000 ======
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;
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 ======
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
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’;
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.
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;
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;
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 ;
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’);
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;
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;
DELETE Statement • This statement to tell SAS to stop processing the current observation. DATA Empfile1; SET Personal; IF ACCOUNT = ‘XEROX’ THEN DELETE; : RUN;
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