Your SlideShare is downloading. ×
Venkata Maguluri
Types of conditional statements in SAS:1) WHERE  a) where “condition”;                                        = where2) IF...
WHERE conditional statement in SAS:1) WHERE    a) where “condition”;                                           = where   ...
IF conditional statement in SAS:2) IF    a) if “condition” then “statement”;                          = if -- then    b) i...
DO conditional statement in SAS:3) DO  a) if “condition” then do; “statement”; end;                 = if – then – do  b) d...
DO conditional statement in SAS:1) DO   The do statement is valid in a data step   It specifies a group of statements to...
   if “Any Questions” then “Drop me a mail”     else if “NO Questions” then “Comment below”   if “Any Questions” the...
Upcoming SlideShare
Loading in...5
×

Conditional statements in sas

5,540

Published on

Published in: Technology, Health & Medicine
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,540
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Conditional statements in sas"

  1. 1. Venkata Maguluri
  2. 2. Types of conditional statements in SAS:1) WHERE a) where “condition”; = where2) 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 -- if3) 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. 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 stepExamples:-/* 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. 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 stepExample:-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.htmhttp://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000202239.htm
  5. 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. 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. 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” 

×