SlideShare una empresa de 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”   

Más contenido relacionado

La actualidad más candente

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
Mark Tabladillo
 
Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sas
halasti
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
venkatam
 

La actualidad más candente (20)

Report procedure
Report procedureReport procedure
Report procedure
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheet
 
Sas Plots Graphs
Sas Plots GraphsSas Plots Graphs
Sas Plots Graphs
 
SAS Proc SQL
SAS Proc SQLSAS Proc SQL
SAS Proc SQL
 
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 Access / SAS Connect
SAS Access / SAS ConnectSAS Access / SAS Connect
SAS Access / SAS Connect
 
SAS Macro
SAS MacroSAS Macro
SAS Macro
 
Utility Procedures in SAS
Utility Procedures in SASUtility Procedures in SAS
Utility Procedures in SAS
 
Introduction to SAS
Introduction to SASIntroduction to SAS
Introduction to SAS
 
Sas cheat
Sas cheatSas cheat
Sas cheat
 
SAS Internal Training
SAS Internal TrainingSAS Internal Training
SAS Internal Training
 
Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sas
 
SAS ODS HTML
SAS ODS HTMLSAS ODS HTML
SAS ODS HTML
 
Understanding sas data step processing.
Understanding sas data step processing.Understanding sas data step processing.
Understanding sas data step processing.
 
SAS Functions
SAS FunctionsSAS Functions
SAS Functions
 
Sas practice programs
Sas practice programsSas practice programs
Sas practice programs
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
 
SAS Ron Cody Solutions for even Number problems from Chapter 7 to 15
SAS Ron Cody Solutions for even Number problems from Chapter 7 to 15SAS Ron Cody Solutions for even Number problems from Chapter 7 to 15
SAS Ron Cody Solutions for even Number problems from Chapter 7 to 15
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
Web 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style SheetsWeb 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style Sheets
 

Destacado

Varun Singh Cv 2008 10 Marketing With Work Ex.2003
Varun Singh Cv 2008 10 Marketing With Work Ex.2003Varun Singh Cv 2008 10 Marketing With Work Ex.2003
Varun Singh Cv 2008 10 Marketing With Work Ex.2003
vrnsingh6
 
Base SAS Exam Questions
Base SAS Exam QuestionsBase SAS Exam Questions
Base SAS Exam Questions
guestc45097
 

Destacado (8)

Varun Singh Cv 2008 10 Marketing With Work Ex.2003
Varun Singh Cv 2008 10 Marketing With Work Ex.2003Varun Singh Cv 2008 10 Marketing With Work Ex.2003
Varun Singh Cv 2008 10 Marketing With Work Ex.2003
 
Basics Of SAS Programming Language
Basics Of SAS Programming LanguageBasics Of SAS Programming Language
Basics Of SAS Programming Language
 
Sas
SasSas
Sas
 
Sass Why for the CSS Guy
Sass Why for the CSS GuySass Why for the CSS Guy
Sass Why for the CSS Guy
 
Learn SAS Programming
Learn SAS ProgrammingLearn SAS Programming
Learn SAS Programming
 
Base SAS Full Sample Paper
Base SAS Full Sample Paper Base SAS Full Sample Paper
Base SAS Full Sample Paper
 
Base SAS Exam Questions
Base SAS Exam QuestionsBase SAS Exam Questions
Base SAS Exam Questions
 
SAS basics Step by step learning
SAS basics Step by step learningSAS basics Step by step learning
SAS basics Step by step learning
 

Similar a Conditional statements in sas

CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
PRN USM
 

Similar 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

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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