How to drop variables from a dataset in SAS Programming? Last Updated : 23 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: SQL DATA outdata; INPUT roll_num gender $ class subj1 subj2 subj3; DATALINES; 21 F 6 10 17 20 13 F 6 21 25 17 19 F 9 19 12 15 10 M 12 7 21 25 25 F 10 15 22 13 13 F 11 20 22 27 ; proc print; run; Output: The main differences between the two are as follows: Scenario: Create a new variable based on existing data and then drops the irrelevant variables By using the DROP statement, we can command SAS to drop variables only when DATA step will be completed. SQL data readin; set outdata; totalsum = sum(subj1, subj2, subj3); drop subj1 subj2 subj3; run; Output: In the above example, we simply ask SAS sum up all the values in variables subj1, subj2 and subj3 to produce a new variable totalsum and then drop the old variables subj1, subj2 and subj3. Consequence of using DROP = Option SQL data readin; set outdata (drop = subj1 subj2 subj3); totalsum = sum(subj1, subj2, subj3); run; Output: The variables subj1, subj2 and subj3 are not available for use after data set outdata has been copied into the new data set readin. Hence totalsum would contain missing values only. DROP statement can be used anywhere in the DATA steps whereas DROP = option must have to follow the SET statement. DROP statement: SQL data readin; set outdata; if gender = 'F'; drop class; run; or SQL data readin; set outdata; drop class; if gender = 'F'; run; DROP = option SQL data readin; set outdata (drop = class); if gender = 'F'; run; Output: Scenario: Dropping variables while printing DROP statement can be used in DATA steps only whereas DROP = option can be used in both DATA steps and PROC steps (for displaying purpose). SQL proc print data = outdata (drop = class); where gender = 'F'; run; Output: Comment More infoAdvertise with us Next Article How to Create or Modify a Variable in SAS Programming? S ShubhamMaurya3 Follow Improve Article Tags : Software Engineering SAS Programming Similar Reads 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 variabl 2 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 SQL data dummy; input a1 a3 a4 a2 a6$ bs$ a5; cards; 2 1 3 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) = 3 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. outd 3 min read Clear variable from Memory in MATLAB Clearing variables from memory, with the help of clearvars operation. The clearvars operation is used to clear the specified variables from memory or from the currently active workspace. Syntax:clearvars variables clearvars -except keepVariables Parameters: This function accepts a parameter. variabl 1 min read SAS | How to read character of varying length using COLON Modifier We generally face this situation when we have company names or both first and last names of a person in our data set. We can use a colon modifier ":" to tell SAS to read variable "Name" until there is a space or other delimiter. The $30. refers to the variable as a character variable having max leng 2 min read Like