SAS Expression and Functions.doc

SAS Expression and Functions.doc - Topic SAS Expression and...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Topic: SAS Expression and Functions 1. Overview of Operators in SAS 2. Infix Operators in SAS 3. SAS expression & Conditional expression (WHERE and IF) 4. Numeric functions 5. SAS Time and Date 6. Character functions 7. Global Statements 1
Image of page 1

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

View Full Document Right Arrow Icon
1. Overview of Operators in SAS Definitions: 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 kinds of operators: prefix operators infix operators. 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 following are examples of prefix operators used with variables, constants, functions, and parenthetic expressions: +y -25 -cos(angle1) +(x*y) 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 Concatenation. When used to perform arithmetic operations, the plus and minus signs are infix operators. 2. Infix Operator 2.1 Arithmetic operators: 2
Image of page 2
Arithmetic Operators Symbol Definition Example * multiplication where bonus = salary * .10; / Division where f = g/h; + Addition where c = a+b; - subtraction where f = g-h; ** exponentiation where y = a**2; 2.2Comparison operators: The following table lists the comparison operators: Comparison Operators Symbol Mnemonic Equivalent Definition Example = EQ equal to where empnum eq 3374; ^= or ~= or ¬= NE not equal to where status ne fulltime; > GT greater than where hiredate gt '01jun1982'd; < LT less than where empnum < 2000; >= GE greater than or equal to where empnum >= 3374; <= LE less than or equal to where empnum <= 3374; IN equal to one from a list of values where state in ('NC','TX'); or num in (‘3’, ‘4’, ‘5’) 2.3Others 2.3.1 IN Operator The IN operator, which is a comparison operator, searches for character and numeric values that are equal to one from a list of values. The list of values must be in parentheses, with each character value in quotation marks and separated by either a comma or blank. 3
Image of page 3

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

View Full Document Right Arrow Icon
For example, suppose you want all sites that are in North Carolina or Texas. You could specify: where state = 'NC' or state = 'TX'; However, the easier way would be to use the IN operator, which says you want any state in the list: where state in ('NC','TX'); In addition, you can use the NOT logical operator to exclude a list. For example, where state not in ('CA', 'TN', 'MA'); Example: data in_ex; input store $ vcr_price vcd_price cd_player_price; datalines ; future_shop 169.99 69.99 79.99 sony_store 179.99 64.99 84.99 radio_shack 159.99 64.99 69.99 three_d 174.99 67.49 74.99 electron 174.99 65.99 69.99 ; data in_ex_2; set in_ex; *where/if vcr_price not in (159.99, 169.99); run ; 2.3.2 Fully-Bounded Range Condition A fully-bounded range condition consists of a variable between two comparison operators, specifying both an upper and lower limit. For example, the following expression returns the employee numbers that fall within the range of 500 to 1000 (inclusive): where 500 <= empnum <= 1000;
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ 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