SlideShare uma empresa Scribd logo
1 de 7
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”   

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Base SAS Statistics Procedures
Base SAS Statistics ProceduresBase SAS Statistics Procedures
Base SAS Statistics Procedures
 
Data Match Merging in SAS
Data Match Merging in SASData Match Merging in SAS
Data Match Merging in SAS
 
Arrays in SAS
Arrays in SASArrays in SAS
Arrays in SAS
 
Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3
 
SAS basics Step by step learning
SAS basics Step by step learningSAS basics Step by step learning
SAS basics Step by step learning
 
Base SAS Full Sample Paper
Base SAS Full Sample Paper Base SAS Full Sample Paper
Base SAS Full Sample Paper
 
Sas practice programs
Sas practice programsSas practice programs
Sas practice programs
 
SAS Programming Notes
SAS Programming NotesSAS Programming Notes
SAS Programming Notes
 
Base SAS Exam Questions
Base SAS Exam QuestionsBase SAS Exam Questions
Base SAS Exam Questions
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processing
 
Sas
SasSas
Sas
 
SAS BASICS
SAS BASICSSAS BASICS
SAS BASICS
 
Utility Procedures in SAS
Utility Procedures in SASUtility Procedures in SAS
Utility Procedures in SAS
 
SAS Proc SQL
SAS Proc SQLSAS Proc SQL
SAS Proc SQL
 
Introduction to SAS
Introduction to SASIntroduction to SAS
Introduction to SAS
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Data Analysis With Pandas
Data Analysis With PandasData Analysis With Pandas
Data Analysis With Pandas
 
Understanding sas data step processing.
Understanding sas data step processing.Understanding sas data step processing.
Understanding sas data step processing.
 
INTRODUCTION TO SAS
INTRODUCTION TO SASINTRODUCTION TO SAS
INTRODUCTION TO SAS
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 

Semelhante a Conditional statements in sas

Semelhante a Conditional statements in sas (20)

control statement
control statement control statement
control statement
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
SPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in CSPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in C
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 
programming c language.
programming c language. programming c language.
programming c language.
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Decision Controls in C++ Programming Lecture
Decision Controls in C++ Programming LectureDecision Controls in C++ Programming Lecture
Decision Controls in C++ Programming Lecture
 
M C6java5
M C6java5M C6java5
M C6java5
 
Decision Structures
Decision StructuresDecision Structures
Decision Structures
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptx
 
L3 control
L3 controlL3 control
L3 control
 
Fcp chapter 2 upto_if_else (2)
Fcp chapter 2 upto_if_else (2)Fcp chapter 2 upto_if_else (2)
Fcp chapter 2 upto_if_else (2)
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 

Último

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

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