If-Then-Else statement in SAS Programming Last Updated : 23 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: SQL Data readin; Input R_Num Subj1-Subj3; cards; 112 21 22 23 105 23 24 26 95 25 25 26 125 26 26 24 122 15 25 16 86 26 16 15 ; Data readin1; Set readin; IF R_Num GE 100; run; Output: IF R_Num GE 100 => This would tell SAS to retain only those Roll numbers whose values are greater than or equal to 100. In other words, you are removing Roll numbers whose values are less than or equal to 100. It could be also done using the IF-THEN DELETE statement. IF-THEN DELETE Syntax: IF (condition is true) THEN (delete the given statements); Example: SQL Data readin; Input R_Num Subj1-Subj3; cards; 112 21 22 23 105 23 24 26 95 25 25 26 125 26 26 24 122 15 25 16 86 26 16 15 ; Data readin1; Set readin; IF R_Num LT 100 THEN DELETE; run; Output: IF R_Num LT 100 THEN DELETE => This would tell SAS to remove all the Roll numbers whose values are less than 100. IF-THEN-ELSE Statement Task 2: Suppose you want to set a tag on all the R_Num. The condition is: If the value of R_Num is less than or equal to 100 sets "Old" tag otherwise set "New" tag. IF (condition is true) THEN (perform this action); ELSE (perform the set of statements that is set when condition is false); SQL Data readin; Input R_Num Subj1-Subj3; cards; 112 21 22 23 105 23 24 26 95 25 25 26 125 26 26 24 122 15 25 16 86 26 16 15 ; Data readin1; Set readin; IF R_Num LE 100 THEN TAG ="Old"; ELSE TAG ="New"; run; Output: IF-THEN-ELSE IF Statement Task 3: Let us assume you are asked to update the TAG column. The conditions for tagging are as follows: If value of R_Num is less than 75 then TAG = "Old" If value of R_Num is greater than or equal to 75 and less than 100 then TAG = "New" If value of R_Num is greater than or equal to 100 then TAG = "Unchecked" IF (condition is true) THEN (perform this action); ELSE IF (perform the set of statements when second condition is true); ELSE IF (perform the set of statements when third condition is true); SQL Data readin; Input R_Num Subj1-Subj3; cards; 112 21 22 23 105 23 24 26 95 25 25 26 125 26 26 24 122 15 25 16 86 26 16 15 ; Data readin1; Set readin; length TAG $20; IF R_Num < 75 THEN TAG ="Old"; ELSE IF 75 <= R_Num < 100 THEN TAG = "New"; ELSE IF R_Num >= 100 THEN TAG ="Unchecked"; run; Output: Comment More infoAdvertise with us Next Article Where Statement in SAS Programming S ShubhamMaurya3 Follow Improve Article Tags : Software Engineering SAS Programming Similar Reads 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. SQL d 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: SQL DATA outdata; INPUT roll_num gender $ class su 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 variabl 2 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 specif 1 min read Contains and Between-And operators in SAS Programming 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. SQL 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; 1 min read MATLAB - Conditional Statements Conditional statements are something that is very basic and important for every programmer. There will be some situations where a program or a particular block has to be executed only when a specific condition is True. These conditional statements will be very handy and fruitful in such situations. 6 min read Like