Open In App

Contains and Between-And operators in SAS Programming

Last Updated : 23 Jul, 2019
Improve
Improve
Like Article
Like
Save
Share
Report
  1. BETWEEN-AND Operator: Between Two Numbers

    Task 1: Suppose you want to select scores whose values are greater than or equal to 50 and less than or equal to 90.




    data readin;
    input name $ Section $ Score;
    cards;
    Raj  A 80
    Atul A 77
    Priya B 45
    Sandeep A 95
    Rahul C 84
    Shreya C 44
    ;
    run;
      
    data readin1;
    set readin;
    where Score between 50 and 90;
    run;

    
    

    where Score between 50 and 90 => This would tell SAS to select values through 50 and 90 (not 51 to 89).

    Output

    This can also be written like:

    where Score GE 50 and Score LE 90;

  2. CONTAINS Operator: Searching specific character

    Task 2: Suppose you want to select only those observations in which students’ name contain ‘hil’.




    data readin;
    input name $ Section $ Score;
    cards;
    Raj  A 80
    Atul A 77
    Priya B 45
    Sandeep A 95
    Rahil C 84
    Sahil B 44
    ;
    run;
      
    data readin1;
    set readin;
    where name contains 'hil';
    run;

    
    

    where name contains ‘hil’ => This would tell SAS to select observations having the values Rahil, Sahil for the variable NAME.

    Note: The CONTAINS operator is case sensitive.

    Output



Similar Reads

IS MISSING and IS NOT MISSING Operators in SAS Programming
IS MISSING Operator: Selecting Missing Values Task 1: Suppose you want to select only those observations in which students did not fill their section information. data readin; input name $ Section $ Score; cards; Raj A 80 Atul . 77 Priya B 45 Sandeep A 95 Rahul . 84 Shreya . 44 ; run; data readin1; set readin; where Section is missing; run; Output:
1 min read
How to import External Data from Excel or Text file into SAS Programming?
PROC IMPORT: It is a procedure to import external files into SAS. It automates importing process. There is no need to specify the variable type and variable-length to import an external file. It supports various formats of files such as excel, txt, etc. Importing an Excel File into SAS: The main keywords used in the following program are: OUT: To s
2 min read
How to Create or Modify a Variable in SAS Programming?
This will help you to create or modify a variable. It is common to define a new variable based on the existing variable. Let's create a dataset In the code below, we are creating a dataset named as Example1 which is going to store on WORK(temporary) library. In this dataset, there would be a variable called OldRate which contains a numeric value. T
2 min read
How to drop variables from a dataset in SAS Programming?
This topic is regarding how to drop variables from a dataset in SAS. It includes various methods to delete variables from data. In SAS, there are two ways to drop variables: DROP = data set option DROP statement Let's start with creating a data set: DATA outdata; INPUT roll_num gender $ class subj1 subj2 subj3; DATALINES; 21 F 6 10 17 20 13 F 6 21
2 min read
Where Statement in SAS Programming
The WHERE statement is a substitute to IF statement when it comes to subsetting a data set. Syntax: WHERE (condition is true) => It refers to subsetting a dataset. Task1 : Suppose you want to select only section A students. You need to filter Section variable equals to A using where clause. data readin; input name $ Section $ Score; cards; Raj A
2 min read
If-Then-Else statement in SAS Programming
Comparison Operators used while using conditional statements. Symbol Mnemonic Meaning = EQ equals ^= or ~= NE not equal > GT greater than < LT less than >= GE greater than or equals <= LE less than or equals in IN selecting multiple values IF statement Syntax: IF (condition is true) => It means subsetting a dataset. Example: Data rea
3 min read
Like Operator in SAS Programming
LIKE Operator: Pattern Matching The LIKE operator used to select data by comparing the values of a character variable to a specified pattern. It is case sensitive. Task 1: To select all students with a name that starts with the letter S. There are two special characters patterns available for specifying a pattern: percent sign (%) - Wildcard Charac
1 min read
SAS | Date Formats and Informats
Informats is used to tell SAS how to read a variable whereas Formats is used to tell SAS how to display or write values of a variable. Informats is basically used when you read in sample data which is being created using CARDS/DATALINES statement or read or import data from either an external file (Text/Excel/CSV). Formats can be used in both Data
2 min read
How to import data into SAS?
Entering Data Directly: You can enter numbers of lines of data directly in SAS program by using a DATALINES statement. The keywords are as follows: DATA: The DATA step always starts with a DATA statement. The purpose of the DATA statement is to tell SAS that you are creating a new data set i.e. outdata. DATA outdata; INPUT: To define the variables
3 min read
SAS | How to specify a list of Variables?
Suppose you have a list of variables. You don't want to type the name of each variable every time to define them within the function or array. You are looking for a shortcut to accomplish this task. Create a dataset with a list of variables data dummy; input a1 a3 a4 a2 a6$ bs$ a5; cards; 2 1 3 5 aa xy 2 2 5 4 1 ab xz 4 2 7 3 9 ac wx 3 ; run; Outpu
2 min read