SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Venkata Maguluri
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
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
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
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
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
   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”   

More Related Content

PPT
Where Vs If Statement
DOCX
Base sas interview questions
PDF
Introduction To Sas
PPT
SAS Functions
PPT
Utility Procedures in SAS
PDF
A Roadmap for SAS Programmers to Clinical Statistical Programming
PDF
Sas cheat
PPT
SAS Macros
Where Vs If Statement
Base sas interview questions
Introduction To Sas
SAS Functions
Utility Procedures in SAS
A Roadmap for SAS Programmers to Clinical Statistical Programming
Sas cheat
SAS Macros

What's hot (20)

PPT
Finding everything about findings about (fa)
PDF
SAS cheat sheet
PDF
SDTMIG_v3.3_FINAL.pdf
PDF
PPT
SDTM - Adverse Events Vs. Clinical Events
PDF
Base SAS Exam Questions
PPT
SAS - overview of SAS
PDF
Clinical sas programmer
PPT
FDA 483 observations in the lab
PPT
SDTM modelling: from study protocol to SDTM-compliant datasets
PPT
Arrays in SAS
PDF
Base SAS Full Sample Paper
PDF
What We Need to Know About CDISC
PPTX
SAS Macro
PDF
Database Lock _ Unlock Procedure_Katalyst HLS
PPT
SAS BASICS
PPT
CDISC SDTM Domain Presentation
PPT
Basics Of SAS Programming Language
PPTX
Introduction to SDTM
PDF
Introduction to SAS
Finding everything about findings about (fa)
SAS cheat sheet
SDTMIG_v3.3_FINAL.pdf
SDTM - Adverse Events Vs. Clinical Events
Base SAS Exam Questions
SAS - overview of SAS
Clinical sas programmer
FDA 483 observations in the lab
SDTM modelling: from study protocol to SDTM-compliant datasets
Arrays in SAS
Base SAS Full Sample Paper
What We Need to Know About CDISC
SAS Macro
Database Lock _ Unlock Procedure_Katalyst HLS
SAS BASICS
CDISC SDTM Domain Presentation
Basics Of SAS Programming Language
Introduction to SDTM
Introduction to SAS
Ad

Viewers also liked (7)

DOC
Varun Singh Cv 2008 10 Marketing With Work Ex.2003
PDF
PDF
SAS Internal Training
KEY
Sass Why for the CSS Guy
DOCX
Learn SAS Programming
PPT
Understanding SAS Data Step Processing
PPTX
SAS basics Step by step learning
Varun Singh Cv 2008 10 Marketing With Work Ex.2003
SAS Internal Training
Sass Why for the CSS Guy
Learn SAS Programming
Understanding SAS Data Step Processing
SAS basics Step by step learning
Ad

Similar to Conditional statements in sas (20)

PDF
control statement
PPTX
Control Statement programming
PDF
SPL 7 | Conditional Statements in C
PPT
control-statements detailed presentation
PPT
Decision making and branching
PPTX
Programming Fundamentals in C++ structures
PPTX
programming c language.
PPT
CONTROLSTRUCTURES.ppt
PPTX
Decision Controls in C++ Programming Lecture
PPT
M C6java5
PPTX
Decision Structures
PPTX
C Programming - Decision making, Looping
PPT
Decision Making and Branching in C
PPT
Selection Control Structures
PPTX
ICSE Class X Conditional Statements in java
PPTX
Conditional Statements.pptx
PPT
L3 control
PPT
Fcp chapter 2 upto_if_else (2)
PPTX
Lecture 2
control statement
Control Statement programming
SPL 7 | Conditional Statements in C
control-statements detailed presentation
Decision making and branching
Programming Fundamentals in C++ structures
programming c language.
CONTROLSTRUCTURES.ppt
Decision Controls in C++ Programming Lecture
M C6java5
Decision Structures
C Programming - Decision making, Looping
Decision Making and Branching in C
Selection Control Structures
ICSE Class X Conditional Statements in java
Conditional Statements.pptx
L3 control
Fcp chapter 2 upto_if_else (2)
Lecture 2

More from venkatam (6)

PPT
Set and Merge
PPT
SAS Macros part 4.1
PPT
Sas macros part 4.1
PPT
SAS Macros part 3
PPT
SAS Macros part 2
PPT
SAS Macros part 1
Set and Merge
SAS Macros part 4.1
Sas macros part 4.1
SAS Macros part 3
SAS Macros part 2
SAS Macros part 1

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Conditional statements in sas

  • 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” 