SAS Data set Programming_Lt4

SAS Data set Programming_Lt4 - SAS Data set Programming...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: SAS Data set Programming Objectives Selecting Variables (DROP/KEEP) Condition Execution ( IF-ELSE) LOOP Execution (DO LOOP) Merging Data Sets Selecting Variables You can use a DROP or KEEP statement in a DATA step to control what variables are written to the new SAS data set. General form of DROP and KEEP statements: DROP variables; KEEP variables ; PDV Flight Date Dest FirstClass Economy Total . . . . E q u i v a l e n t Selecting Variables data onboard; set mylib.dfwlax; drop FirstClass Economy; Total=FirstClass+Economy; run; keep Flight Date Dest Total; D D Do not store the variables FirstClass and Economy in the data set. Conditional Processing Conditional Execution Expression contains operands and operators that form a set of instructions that produce a value. Operators are symbols that request a comparison a logical operation an arithmetic calculation SAS functions. Operands are variable names constants. General form of IF-THEN and ELSE statements: IF expression THEN statement ; ELSE statement ; Only one executable statement is allowed on an IF-THEN or ELSE statement. data mylib.DWMId_grd; set dw_mrk1; if Dwmid >= 85 then grade= 'A' ; else if dwmid >= 70 and dwmid < 85 then grade = 'B' ; else if dwmid >= 55 and dwmid < 70 then grade= 'C' ; else if dwmid > 39 and dwmid < 55 then grade= 'D' ; else grade= 'E' ; run ; You can use the DO and END statements to execute a group of statements based on a condition. General form of the DO and END statements: Conditional Execution IF expression THEN DO ; executable statements END ; ELSE DO ; executable statements END ; data mylib.x_dt; set mylib.d1; if x ge 85 then do ; gr= 'A' ; result ='distinction'; end ; else if (x ge 70 and x lt 85 ) then do ; gr= 'B' ; result = 'First Class'; end ; else if x GE 55 and x < 70 then do; gr= 'D' ; resul t='Above Average'; end; else if x GE 40 and x < 54 then do; gr= 'D' ; resul t='Average'; end; else do ; grade= 'D' ; result ='FAIL'; end; r un ; Conditional Expression Using Select data mylib.x_sel; set mylib.d1 ; select ; when (x>= 85 )gr= 'A' ; when (x>= 70 and x < 85 ) gr= 'B' ; when (x>= 55 and x < 70 ) gr= 'C' ; when (x>= 40 and x < 55 ) gr= 'D' ; otherwise gr= 'E' ; end ; run ; data mylib.x_dt1 mylib.x_dt2 mylib.x_dt3; set mylib.d1; if x gt 85 then do ; gr= 'A' ; output mylib.x_dt2; end ; else if (x gt 70 and x lt 84 ) then do ; gr= 'B' ; output mylib.x_dt1; end ; else do ; gr= 'c' ; output mylib.x_dt3; end ; run ; DO LOOP EXECUTION DO LOOP Execution DATA mylib.x_doLoop; SET mylib.d1; y=x; do i= 1 to 4 by + 1 ; y=y+i; end ; drop i; RUN ; PROC PRINT data =mylib.x_doLoop; RUN ; DO LOOP Execution Compute Factorial using DO LOOP data mylib.x_fact1; set mylib.x_fact; fact1= 1 ; do i=x to 1 by- 1 ; fact1=fact1*i; end ; drop i; run ; proc print data =mylib.x_fact1; run ; data mylib.x_fact3; input x @; fact= 1 ; do i=x to 1 by- 1 ; fact=fact*i; end ; drop i; datalines ; 4 5 6 ; run ; proc print data =mylib.x_fact3; run ; data...
View Full Document

This note was uploaded on 07/15/2011 for the course ECO 2023 taught by Professor Mr.raza during the Summer '10 term at FAU.

Page1 / 121

SAS Data set Programming_Lt4 - SAS Data set Programming...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online