IF, IF-THEN and IF-THEN-ELSE Statements

Contents Index


Conditional statements (if-then statements, if-then-else statements) are often used to assign values to variables. Example:

data new;
input prefix age sex $;
if prefix=821 then city='auburn';
if age <30 then young=1;
else young=0;
if age<30 and sex='f' then yw=1;
if age>80 or prefix='749' then nogood=1;
.....

The logical connectives AND and OR are used to create compound tests, as illustrated above.

A counterless do-loop can be used to have more complicated processing after an if-branch. Example:

if age<30 then do;
	if income<20000 then cat=1;
	if income>20000 and income <30000 then cat=2;
	end;
....

The return statement can be used to branch to the bottom of the data step program.

Do-loops and if-then statements can be nested.


Contents Index

Copyright © 1997 by Jerry Alan Veeh. All rights reserved.