SAS_BASE_3 final.docx - TOPIC 3 Managing Data 1 SAS...

This preview shows page 1 - 4 out of 58 pages.

TOPIC 3 Managing Data 1. SAS Operators in expressions and SAS Functions ...................................................................... 3 1.1 SAS Operators in expressions ............................................................................................... 3 1.1.1 Prefix operator ................................................................................................................ 3 1.1.2 Infix operator .................................................................................................................. 3 1.1.2.1 Arithmetic operators ................................................................................................ 3 1.1.2.2 Comparison Operators ............................................................................................. 4 1.1.2.3 Logical (Boolean) Operators ................................................................................... 5 1.1.2.4 The MIN and MAX Operators ................................................................................. 5 1.1.2.5 The Concatenation Operator .................................................................................... 6 1.2 SAS Functions ....................................................................................................................... 6 1.2.1 Numeric Functions .......................................................................................................... 6 1.2.1.1 SUM function .......................................................................................................... 7 1.2.1.2 ROUND and INT function ...................................................................................... 8 1.2.1.3 MIN, MAX, MEAN, MEDIAN function ................................................................ 9 1.2.1.4 ABS, SQRT, EXP, and LOG functions .................................................................... 9 1.2.2 Character Functions ........................................................................................................ 9 1.2.2.1 Put and Input Function ............................................................................................. 9 1.2.2.2 UPCASE/LOWCASE Function ............................................................................ 10 1.2.2.3 SUBSTR Function ................................................................................................. 10 1.2.2.4 SCAN Function ..................................................................................................... 12 1.2.2.5 TRANWRD Function ............................................................................................ 13 1.2.2.6 TRIM Function ...................................................................................................... 14 1.2.2.7 COMPBL Function ................................................................................................ 15 1.2.2.8 COMPRESS Function ........................................................................................... 16 1.2.2.9 CAT/CATT/CATS/CATX Function ....................................................................... 17 1.2.2.10 INDEX, INDEXC and INDEXW Function ......................................................... 18 1.2.2.11 FIND Function ..................................................................................................... 19 1.2.2.12VERIFY Function ................................................................................................. 20 1.2.3 SAS Date/Time Functions ............................................................................................ 20 1.2.3.1 SAS Date and Time Values .................................................................................... 20 1.2.3.2 Date functions ........................................................................................................ 24 1.2.3.3 Date, Time, and Datetime Constants ..................................................................... 27 1
Image of page 1

Subscribe to view the full document.

2. Data Step Statements ................................................................................................................. 28 2.1 Assignment Statement ......................................................................................................... 29 2.2 SUM Statement .................................................................................................................... 30 2.3 RETAIN Statement .............................................................................................................. 30 2.4 LENGTH Statement ............................................................................................................ 32 2.5 BY Statement ....................................................................................................................... 33 2.6 OUTPUT Statement ............................................................................................................. 34 2.7 RETURN Statement ............................................................................................................ 35 2.8 KEEP/DROP Statement ....................................................................................................... 35 3. Conditionally execute SAS statements ...................................................................................... 36 3.1 IF-THEN Statement ............................................................................................................. 36 3.2 IF-THEN/ELSE Statement .................................................................................................. 38 3.3 IF-THEN-DO Statement ...................................................................................................... 40 3.4 SELECT Statement .............................................................................................................. 40 4. Do Loops ................................................................................................................................... 43 4.1 General Form of Iterative Do Loops ................................................................................... 43 4.1.1 Use a list of items for the value of start ........................................................................ 43 4.1.2 Use start TO stop by increment .................................................................................... 44 4.2 Nesting Do Loops ................................................................................................................ 45 4.3 Conditionally Executing Do Loops ..................................................................................... 46 4.3.1 Do while ........................................................................................................................ 46 4.3.2 Do until ......................................................................................................................... 46 5. Arrays ......................................................................................................................................... 47 6. PROC SORT .............................................................................................................................. 52 6.1 Sorting Orders ...................................................................................................................... 52 6.1.1 Numeric Variables ......................................................................................................... 52 6.1.2 Character Variables ....................................................................................................... 52 6.2 NODUPKEY/NODUP/NODUPRES / DUPOUT options .................................................. 54 7. PROC FORMAT ........................................................................................................................ 56 2
Image of page 2
1. SAS Operators in expressions and SAS Functions 1.1 SAS Operators in expressions A SAS operator is a symbol that represents a comparison, arithmetic calculation, or logical operation; a SAS function; or grouping parentheses. SAS uses two major types of operators: prefix operators infix operators SAS Expressions is generally a sequence of operands and operators that form a set of instructions that are performed to produce a resulting value. You use expressions in SAS program statements to create variables, assign values, calculate new values, transform variables, and perform conditional processing. Operand: constants or variables that can be numeric or character. Operators: symbols that represent a comparison, arithmetic calculation, or logical operation; a SAS function; or grouping parentheses. 1.1.1 Prefix operator A prefix operator is an operator that is applied to the variable, constant, function, or parenthetic expression that immediately follows it. The plus sign (+) and minus sign (-) can be used as prefix operators. The word NOT and its equivalent symbols are also prefix operators. The following are examples of prefix operators used with variables, constants, functions, and parenthetic expressions: +y -25 -cos(angle1) +(x*y) 1.1.2 Infix operator An infix operator applies to the operands on each side of it, for example, 6<8. Infix operators include the following: arithmetic comparison logical, or Boolean minimum maximum 3
Image of page 3

Subscribe to view the full document.

Image of page 4
  • Fall '14
  • Test, Missing values, Calendar date

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern