2. Types of conditional statements in SAS:
1) WHERE
a) where “condition”; = where
2) IF
a) if “condition” then “statement”; = if -- then
b) if “condition” then “statement”; else “statement”; = if – then – else
c) if “condition” then “statement”; else if “statement”; = if – then – else -- if
3) DO
a) if “condition” then do; “statement”; end; = if – then – do
b) do while “condition”; “statement”; end; = do while
c) do until “condition” ; “statement”; end; = do until
d) do “var” = “start” to “end”; “statement”; end; = do loop
e) do “var” = “start” to “end” by “inc”; “statement”; end; = do loop
f) do over “array”; “statement”; end; = do loop
3. WHERE conditional statement in SAS:
1) WHERE
a) where “condition”; = where
It is used to select observations that meet a particular condition in a dataset
The conditions in where statement can be numeric or character expression
You can use only one where statement in a data step or in a proc step
Examples:-
/* Selecting observations in a data step */
data dm1;
set derived.dm;
where . < 18 <= age <= 55 and gender=“M”;
run;
/* Selecting observations for processing in a proc step */
proc means data=derived.dm;
where . < age <= 55 and gender=“F”;
run;
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000202951.htm
4. IF conditional statement in SAS:
2) IF
a) if “condition” then “statement”; = if -- then
b) if “condition” then “statement”; else “statement”; = if – then – else
c) if “condition” then “statement”; else if “statement”; = if – then – else – if
Processes only those observations that meet the condition
The conditions in if statement can be numeric or character expression
You can use more than one if statement in a data step
Example:-
data dm1;
set dm;
if citycode=5564 then city=„Mumbai‟ = if -- then
if . < age <= 25 then young=„Yes‟; = if – then – else
else young=„No‟;
if 18 <= age <= 25 then agegrp=‟18 – 25 years‟; = if – then – else – if
else if 26 <= age <= 35 then agegrp=„26 – 35 years‟;
else if 36 <= age <= 45 then agegrp=„36 – 45 years‟;
else agegrp=„> 46 years‟;
run;
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000201978.htm
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000202239.htm
5. DO conditional statement in SAS:
3) DO
a) if “condition” then do; “statement”; end; = if – then – do
b) do while “condition”; “statement”; end; = do while
c) do until “condition” ; “statement”; end; = do until
d) do “var” = “start” to “end”; “statement”; end; = do loop
e) do “var” = “start” to “end” by “inc”; “statement”; end; = do loop
f) do over “array”; “statement”; end; = do loop
6. DO conditional statement in SAS:
1) DO
The do statement is valid in a data step
It specifies a group of statements to be executed as a unit
Every do loop has a corresponding end statement
The statements between the do and end statements are called a DO group
You can nest do statements within do groups
A simple do statement is often used within if – then – else statements to designate a group
of statements to be executed depending on whether the if condition is true or false
do until statement executes statements in a do loop repetitively until a condition is
true, checking the condition after each iteration of the do loop
do while statement executes statements in a do loop repetitively while a condition is
true, checking the condition before each iteration of the do loop
The do until statement evaluates the condition at the bottom of the loop
The do while statement evaluates the condition at the top of the loop
do over loop used to perform the operations in the do loop over ALL elements in the array
Within a single do loop multiple arrays can be referenced and operations on different
arrays can be performed
7. if “Any Questions” then “Drop me a mail”
else if “NO Questions” then “Comment below”
if “Any Questions” then
do “Ask and Drop me a mail”
end
else if “NO Questions” then “Leave your comment”