SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Introduction to Where
     Expressions
         Mark Tabladillo, Ph.D.
Software Developer, MarkTab Consulting
Associate Faculty University of Phoenix
          Faculty,
           January 30, 2007
Introduction
• WHERE expressions allow for processing
  subsets of observations
• WHERE expressions can be used in the
  DATA step or with PROC (procedure)
  statements
• This presentation will contain a series of
  features and examples of the WHERE
                    p
  expression
• We end with some intensive macros
WHERE-expression Processing
 WHERE expression
• Enables us to conditionally select a subset
  of observations, so that SAS processes
  only the observations that meet a set of
  specified conditions.




http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999253.htm
Work Sales Dataset
     Work.Sales
data work.sales (drop=i randomState);
    length state $2 sales 8 randomState 3;
    do i = 1 to 2500;
         randomState = round(rand('gaussian',3,1)+0.5);
         if randomState in (1,2,3,4,5) then do;
                             (        )
               select(randomState);
                    when(1) state='TN';
                    when(2) state='AL';
                    when(3) state= GA ;
                             state='GA';
                    when(4) state='FL';
                    when(5) state='MS';
               end;
               sales = int(rand('gaussian',1000000,500000));
               output work.sales;
         end;
    end;
    run;
Data Set Option or Statement
   data work.highSales;
           set work.sales (where=(sales>1500000));
           run;

   data work highSales;
        work.highSales;
           set work.sales;
           where sales>1500000;
           run;

   proc means data=work.sales;
          where sales>1500000;
          run;
             ;
Data Set Option or Statement
   data work.lowSales;
           set work.sales (where=(sales<0));
           run;

   data work lowSales;
        work.lowSales;
           set work.sales;
           where sales<0;
           run;

   proc means data=work.sales (where=(sales<0));
          run;
Multiple Comparisons
data work.highFloridaSales;
        set work.sales (where=(sales>1500000 and state = 'FL'));
        run;

data work highFloridaSales;
     work.highFloridaSales;
        set work.sales;
        where sales>1500000 and state = 'FL';
        run;

proc freq data=work.sales;
        tables state;
        where sales>1500000 and state = 'FL';
                                            ;
        run;
SAS Functions
data work.highFloridaSales;
        set work.sales (where=(sales>1500000 and substr(state,1,1) = 'F'));
        run;

data work highFloridaSales;
     work.highFloridaSales;
        set work.sales;
        where sales>1500000 and substr(state,1,1) = 'F';
        run;

proc means data=work.sales;
       where sales>1500000 and substr(state,1,1) = 'F';
       run;
          ;
Comparison Operators
Priority     Order of               Symbols Mnemonic
                Evaluation                    Equivalent
Group I      right to left             **
                                       +
                                        -
                                      ˆ¬~   NOT
                                       ><   MIN
                                       <>   MAX


http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000780367.htm
Comparison Operators
Priority Order of                  Symbols Mnemonic
            Evaluation                      Equivalent
Group II left to right                *
                                      /
Group        left to right            +
  III
                                          -
Group        left to right             || ¦¦ !!
  IV

http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000780367.htm
Comparison Operators
Priority     Order of               Symbols Mnemonic
                Evaluation                    Equivalent
Group        left to right             <    LT
  V
                                         <=       LE
                                         =        EQ
                                         ¬=       NE
                                         >=       GE
                                         >        GT
                                                  IN

http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000780367.htm
Comparison Operators
Priority     Order of               Symbols Mnemonic
               Evaluation                    Equivalent
Group        left to right               &        AND
  VI
Group        left to right              |¦!       OR
  VII




http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000780367.htm
Comparison Operators
data work.extremeNonGeorgia;
        set work.sales
          (where=((sales<0 | sales>1500000) and state in ('TN','AL','FL','MS')));
        run;

data work.extremeNonGeorgia;
        set work.sales;
        where (sales<0 | sales>1500000) and state in ('TN','AL','FL','MS');
        run;

data work.extremeNonGeorgia;
        set work.sales;
                      ;
        where ^ (0 <= sales <= 1500000) & state ne 'GA';
        run;



 http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
“Between And”
                    Between And
data work.boundedNonGeorgia;
        set work.sales (where=((sales between 1000000 and 1500000) &
                 state in ('TN','AL','FL','MS')));
        run;

data work.boundedNonGeorgia;
        set work.sales;
        where (sales between 1000000 and 1500000) &
                 state in ('TN','AL','FL','MS');
                  t t i ('TN' 'AL' 'FL' 'MS')
        run;




http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
Contains ?
           data work.LStates;
                   set work.sales (where=(state contains 'L'));
                   run;

           data work LStates;
                work.LStates;
                   set work.sales;
                   where state contains 'L';
                   run;

           data work.LStates;
                   set work.sales;
                   where state ? 'L';
                                    ;
                   run;




http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
Is Null/Is Missing
            data work.nullStates;
                    set work.sales (where=(state is null));
                    run;

            data work.missingStates;
                    se o sa es (where=(state s ss g));
                    set work.sales ( e e (s a e is missing));
                    run;

            data work.nullSales;
                    set work.sales;
                        work sales;
                    where sales is missing;
                    run;

            data work.nonNullSales;
                    set work.sales;
                    where sales is not missing;
                    run;
http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
Like
         data work.likeL;
                 set work.sales (where=(state like '%L'));
                      work sales
                 run;

         data work.likeL;
                 set work.sales (where=(state like quot;%Lquot;));
                 run;

         data work likeL;
              work.likeL;
                 set work.sales (where=(state like quot;%%Lquot;));
                 run;

         data work.notLikeG;
                 set work.sales;
                 where state not like 'G_';
                 run;

http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
Sounds Like (Soundex)
        data work.soundsLikeFill;
                set work.sales (where=(state =* 'fill'));
                run;

        data work notSoundsLikeTin;
             work.notSoundsLikeTin;
                set work.sales;
                where state not =* 'tin';
                run;




http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
“Same And”
                        Same And
data work.boundedNonGeorgia;
        set work.sales (where=((sales between 1000000 and 1500000) &
                 state in ('TN','AL','FL','MS')));
        run;

data work.boundedNonGeorgia;
        set work.sales;
        where (sales between 1000000 and 1500000);
        where same and state i ('TN' 'AL' 'FL' 'MS')
          h             d t t in ('TN','AL','FL','MS');
        run;

data work.boundedNonGeorgia;
                         g ;
        set work.sales;
        where same and (sales between 1000000 and 1500000);
        where same and state in ('TN','AL','FL','MS');
        run;
http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
WHERE vs. Subsetting IF
               vs
Task                                                         Method


Make the selection in a procedure without using a            WHERE expression
   preceding DATA step
Take advantage of the efficiency available with an indexed   WHERE expression
   data set
Use one of a group of special operators, such as             WHERE expression
   BETWEEN-AND, CONTAINS, IS MISSING or IS
   NULL, LIKE, SAME-AND, and Sounds-Like
B    th     l ti           thi   th th          i bl   l     b tti
Base the selection on anything other than a variable value subsetting IF
   that already exists in a SAS data set. For example, you
   can select a value that is read from raw data, or a
   value that is calculated or assigned during the course
   of the DATA step
    f th          t
Make the selection at some point during a DATA step          subsetting IF
   rather than at the beginning
Execute the selection conditionally                          subsetting IF

http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a001000521.htm
Intensive Dataset Generation
%macro OurCentury();
%local year interest;
       y             ;
%do year = 2001 %to 2100;
    %let interest = %sysfunc(compound(1,.,0.05,%eval(&year.-2001)));
    data work.sales&year. (drop=i randomState index=(state sales));
         length state $2 stateName $20 sales 8 randomState 3;
             g                                                    ;
         do i = 1 to 2500;
               randomState = round(56*rand('uniform')+0.5);
               if randomState <= 56 and randomState not in (3,7,14,43,52) then do;
                       state = fipstate(randomState);
                                 p     (            )
                       stateName = fipnameL(randomState);
                       sales = int(rand('gaussian',1000000*&interest.,500000*&interest.));
                       output work.sales&year.;
               end;
         end;
         run;
%end;
%mend OurCentury;   y
%OurCentury;
Year/State Datasets
%macro SalesByYearState();
%local year stateCode state;
%do year = 2001 %to 2100;
    %do stateCode = 1 %to 56;
         %if &stateCode ne 3 & &stateCode ne 7 & &stateCode. ne 14 &
             &stateCode.         &stateCode.         &stateCode
              &stateCode. ne 43 & &stateCode. ne 52 %then %do;
              %let state = %sysfunc(fipstate(&stateCode.));
              data work.sales&year.&state.;
                  set work.sales&year.;
                     t    k l &
                  where state = quot;&state.quot;;
                  run;
         %end; ;
    %end;
%end;
%mend SalesByYearState;
%SalesByYearState;
Year/State High Sales Datasets
%macro HighSalesByYearState();
%local year stateCode state interest keepDataset;
%do year = 2001 %to 2100;
     %let interest = %sysfunc(compound(1,.,0.05,%eval(&year.-2001)));
     %do stateCode = 1 %to 56;
           %if &stateCode. ne 3 & &stateCode. ne 7 & &stateCode. ne 14 & &stateCode. ne 43 &
                 &stateCode. ne 52 %then %do;
                 %let state = %sysfunc(fipstate(&stateCode.));
                 %let keepDataset = 0;
                 data work.sales&year.&state.high;
                       set work.sales&year.;
                       where state = quot;&state.quot; and sales > 2000000*&i t
                         h      t t    quot;& t t quot; d l          2000000*&interest.;
                                                                             t
                       call symput('keepDataset',left('1'));
                       run;
                 %if not(&keepDataset.) %then %do;
                       p
                       proc datasets lib=work nolist;
                              delete sales&year.&state.high;
                              run; quit;
                 %end;
           %end;
     %end;
%end;
%mend HighSalesByYearState;
%HighSalesByYearState;
Conclusion
• The WHERE expression allows for
  efficient observation processing in the
  DATA step and the PROC statements
• The SAS System Documentation provides
  specific details on the syntax
• Using macros increases the processing
  power of WHERE expressions
           f                  i
Contact Information
• Mark Tabladillo
  MarkTab Consulting
  http://www.marktab.com/
  http://www marktab com/

Más contenido relacionado

Similar a Introduction to SAS System Where Expressions

iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기Wanbok Choi
 
解决Ora 14098分区交换索引不匹配错误
解决Ora 14098分区交换索引不匹配错误解决Ora 14098分区交换索引不匹配错误
解决Ora 14098分区交换索引不匹配错误maclean liu
 
Adding Statistical Functionality to the DATA Step with PROC FCMP
Adding Statistical Functionality to the DATA Step with PROC FCMPAdding Statistical Functionality to the DATA Step with PROC FCMP
Adding Statistical Functionality to the DATA Step with PROC FCMPJacques Rioux
 
foreach (DataRow dataRow in dataTable.Rows) .docx
            foreach (DataRow dataRow in dataTable.Rows)        .docx            foreach (DataRow dataRow in dataTable.Rows)        .docx
foreach (DataRow dataRow in dataTable.Rows) .docxjoyjonna282
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Roel Hartman
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptGuy Royse
 
Scti 2011 minicurso jquery
Scti 2011 minicurso jqueryScti 2011 minicurso jquery
Scti 2011 minicurso jqueryciberglo
 
The journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationThe journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationSian Lerk Lau
 
Netezza technicaloverviewportugues
Netezza technicaloverviewportugues Netezza technicaloverviewportugues
Netezza technicaloverviewportugues hdkid82
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2tonvanbart
 
Java.script
Java.scriptJava.script
Java.scriptg Nama
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
How to generate a 100+ page website using parameterisation in R
How to generate a 100+ page website using parameterisation in RHow to generate a 100+ page website using parameterisation in R
How to generate a 100+ page website using parameterisation in RPaul Bradshaw
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfacesmaccman
 
Chris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql PortfolioChris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql Portfolioclmcglothen
 

Similar a Introduction to SAS System Where Expressions (20)

iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기
 
解决Ora 14098分区交换索引不匹配错误
解决Ora 14098分区交换索引不匹配错误解决Ora 14098分区交换索引不匹配错误
解决Ora 14098分区交换索引不匹配错误
 
Adding Statistical Functionality to the DATA Step with PROC FCMP
Adding Statistical Functionality to the DATA Step with PROC FCMPAdding Statistical Functionality to the DATA Step with PROC FCMP
Adding Statistical Functionality to the DATA Step with PROC FCMP
 
foreach (DataRow dataRow in dataTable.Rows) .docx
            foreach (DataRow dataRow in dataTable.Rows)        .docx            foreach (DataRow dataRow in dataTable.Rows)        .docx
foreach (DataRow dataRow in dataTable.Rows) .docx
 
Web lab programs
Web lab programsWeb lab programs
Web lab programs
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
 
Scti 2011 minicurso jquery
Scti 2011 minicurso jqueryScti 2011 minicurso jquery
Scti 2011 minicurso jquery
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
The journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationThe journey of an (un)orthodox optimization
The journey of an (un)orthodox optimization
 
Netezza technicaloverviewportugues
Netezza technicaloverviewportugues Netezza technicaloverviewportugues
Netezza technicaloverviewportugues
 
Speed of Lightning
Speed of LightningSpeed of Lightning
Speed of Lightning
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
 
Java.script
Java.scriptJava.script
Java.script
 
Html
HtmlHtml
Html
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
How to generate a 100+ page website using parameterisation in R
How to generate a 100+ page website using parameterisation in RHow to generate a 100+ page website using parameterisation in R
How to generate a 100+ page website using parameterisation in R
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfaces
 
Chris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql PortfolioChris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql Portfolio
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 

Más de Mark Tabladillo

How to find low-cost or free data science resources 202006
How to find low-cost or free data science resources 202006How to find low-cost or free data science resources 202006
How to find low-cost or free data science resources 202006Mark Tabladillo
 
Microsoft Build 2020: Data Science Recap
Microsoft Build 2020: Data Science RecapMicrosoft Build 2020: Data Science Recap
Microsoft Build 2020: Data Science RecapMark Tabladillo
 
201909 Automated ML for Developers
201909 Automated ML for Developers201909 Automated ML for Developers
201909 Automated ML for DevelopersMark Tabladillo
 
201908 Overview of Automated ML
201908 Overview of Automated ML201908 Overview of Automated ML
201908 Overview of Automated MLMark Tabladillo
 
201906 01 Introduction to ML.NET 1.0
201906 01 Introduction to ML.NET 1.0201906 01 Introduction to ML.NET 1.0
201906 01 Introduction to ML.NET 1.0Mark Tabladillo
 
201906 04 Overview of Automated ML June 2019
201906 04 Overview of Automated ML June 2019201906 04 Overview of Automated ML June 2019
201906 04 Overview of Automated ML June 2019Mark Tabladillo
 
201906 03 Introduction to NimbusML
201906 03 Introduction to NimbusML201906 03 Introduction to NimbusML
201906 03 Introduction to NimbusMLMark Tabladillo
 
201906 02 Introduction to AutoML with ML.NET 1.0
201906 02 Introduction to AutoML with ML.NET 1.0201906 02 Introduction to AutoML with ML.NET 1.0
201906 02 Introduction to AutoML with ML.NET 1.0Mark Tabladillo
 
201905 Azure Databricks for Machine Learning
201905 Azure Databricks for Machine Learning201905 Azure Databricks for Machine Learning
201905 Azure Databricks for Machine LearningMark Tabladillo
 
201905 Azure Certification DP-100: Designing and Implementing a Data Science ...
201905 Azure Certification DP-100: Designing and Implementing a Data Science ...201905 Azure Certification DP-100: Designing and Implementing a Data Science ...
201905 Azure Certification DP-100: Designing and Implementing a Data Science ...Mark Tabladillo
 
Big Data Advanced Analytics on Microsoft Azure 201904
Big Data Advanced Analytics on Microsoft Azure 201904Big Data Advanced Analytics on Microsoft Azure 201904
Big Data Advanced Analytics on Microsoft Azure 201904Mark Tabladillo
 
Managing Enterprise Data Science 201904
Managing Enterprise Data Science 201904Managing Enterprise Data Science 201904
Managing Enterprise Data Science 201904Mark Tabladillo
 
Training of Python scikit-learn models on Azure
Training of Python scikit-learn models on AzureTraining of Python scikit-learn models on Azure
Training of Python scikit-learn models on AzureMark Tabladillo
 
Big Data Adavnced Analytics on Microsoft Azure
Big Data Adavnced Analytics on Microsoft AzureBig Data Adavnced Analytics on Microsoft Azure
Big Data Adavnced Analytics on Microsoft AzureMark Tabladillo
 
Advanced Analytics with Power BI 201808
Advanced Analytics with Power BI 201808Advanced Analytics with Power BI 201808
Advanced Analytics with Power BI 201808Mark Tabladillo
 
Microsoft Cognitive Toolkit (Atlanta Code Camp 2017)
Microsoft Cognitive Toolkit (Atlanta Code Camp 2017)Microsoft Cognitive Toolkit (Atlanta Code Camp 2017)
Microsoft Cognitive Toolkit (Atlanta Code Camp 2017)Mark Tabladillo
 
Machine learning services with SQL Server 2017
Machine learning services with SQL Server 2017Machine learning services with SQL Server 2017
Machine learning services with SQL Server 2017Mark Tabladillo
 
Microsoft Technologies for Data Science 201612
Microsoft Technologies for Data Science 201612Microsoft Technologies for Data Science 201612
Microsoft Technologies for Data Science 201612Mark Tabladillo
 
How Big Companies plan to use Our Big Data 201610
How Big Companies plan to use Our Big Data 201610How Big Companies plan to use Our Big Data 201610
How Big Companies plan to use Our Big Data 201610Mark Tabladillo
 
Georgia Tech Data Science Hackathon September 2016
Georgia Tech Data Science Hackathon September 2016Georgia Tech Data Science Hackathon September 2016
Georgia Tech Data Science Hackathon September 2016Mark Tabladillo
 

Más de Mark Tabladillo (20)

How to find low-cost or free data science resources 202006
How to find low-cost or free data science resources 202006How to find low-cost or free data science resources 202006
How to find low-cost or free data science resources 202006
 
Microsoft Build 2020: Data Science Recap
Microsoft Build 2020: Data Science RecapMicrosoft Build 2020: Data Science Recap
Microsoft Build 2020: Data Science Recap
 
201909 Automated ML for Developers
201909 Automated ML for Developers201909 Automated ML for Developers
201909 Automated ML for Developers
 
201908 Overview of Automated ML
201908 Overview of Automated ML201908 Overview of Automated ML
201908 Overview of Automated ML
 
201906 01 Introduction to ML.NET 1.0
201906 01 Introduction to ML.NET 1.0201906 01 Introduction to ML.NET 1.0
201906 01 Introduction to ML.NET 1.0
 
201906 04 Overview of Automated ML June 2019
201906 04 Overview of Automated ML June 2019201906 04 Overview of Automated ML June 2019
201906 04 Overview of Automated ML June 2019
 
201906 03 Introduction to NimbusML
201906 03 Introduction to NimbusML201906 03 Introduction to NimbusML
201906 03 Introduction to NimbusML
 
201906 02 Introduction to AutoML with ML.NET 1.0
201906 02 Introduction to AutoML with ML.NET 1.0201906 02 Introduction to AutoML with ML.NET 1.0
201906 02 Introduction to AutoML with ML.NET 1.0
 
201905 Azure Databricks for Machine Learning
201905 Azure Databricks for Machine Learning201905 Azure Databricks for Machine Learning
201905 Azure Databricks for Machine Learning
 
201905 Azure Certification DP-100: Designing and Implementing a Data Science ...
201905 Azure Certification DP-100: Designing and Implementing a Data Science ...201905 Azure Certification DP-100: Designing and Implementing a Data Science ...
201905 Azure Certification DP-100: Designing and Implementing a Data Science ...
 
Big Data Advanced Analytics on Microsoft Azure 201904
Big Data Advanced Analytics on Microsoft Azure 201904Big Data Advanced Analytics on Microsoft Azure 201904
Big Data Advanced Analytics on Microsoft Azure 201904
 
Managing Enterprise Data Science 201904
Managing Enterprise Data Science 201904Managing Enterprise Data Science 201904
Managing Enterprise Data Science 201904
 
Training of Python scikit-learn models on Azure
Training of Python scikit-learn models on AzureTraining of Python scikit-learn models on Azure
Training of Python scikit-learn models on Azure
 
Big Data Adavnced Analytics on Microsoft Azure
Big Data Adavnced Analytics on Microsoft AzureBig Data Adavnced Analytics on Microsoft Azure
Big Data Adavnced Analytics on Microsoft Azure
 
Advanced Analytics with Power BI 201808
Advanced Analytics with Power BI 201808Advanced Analytics with Power BI 201808
Advanced Analytics with Power BI 201808
 
Microsoft Cognitive Toolkit (Atlanta Code Camp 2017)
Microsoft Cognitive Toolkit (Atlanta Code Camp 2017)Microsoft Cognitive Toolkit (Atlanta Code Camp 2017)
Microsoft Cognitive Toolkit (Atlanta Code Camp 2017)
 
Machine learning services with SQL Server 2017
Machine learning services with SQL Server 2017Machine learning services with SQL Server 2017
Machine learning services with SQL Server 2017
 
Microsoft Technologies for Data Science 201612
Microsoft Technologies for Data Science 201612Microsoft Technologies for Data Science 201612
Microsoft Technologies for Data Science 201612
 
How Big Companies plan to use Our Big Data 201610
How Big Companies plan to use Our Big Data 201610How Big Companies plan to use Our Big Data 201610
How Big Companies plan to use Our Big Data 201610
 
Georgia Tech Data Science Hackathon September 2016
Georgia Tech Data Science Hackathon September 2016Georgia Tech Data Science Hackathon September 2016
Georgia Tech Data Science Hackathon September 2016
 

Último

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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 Takeoffsammart93
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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, Adobeapidays
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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 DevelopmentsTrustArc
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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 RobisonAnna Loughnan Colquhoun
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - 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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Introduction to SAS System Where Expressions

  • 1. Introduction to Where Expressions Mark Tabladillo, Ph.D. Software Developer, MarkTab Consulting Associate Faculty University of Phoenix Faculty, January 30, 2007
  • 2. Introduction • WHERE expressions allow for processing subsets of observations • WHERE expressions can be used in the DATA step or with PROC (procedure) statements • This presentation will contain a series of features and examples of the WHERE p expression • We end with some intensive macros
  • 3. WHERE-expression Processing WHERE expression • Enables us to conditionally select a subset of observations, so that SAS processes only the observations that meet a set of specified conditions. http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999253.htm
  • 4. Work Sales Dataset Work.Sales data work.sales (drop=i randomState); length state $2 sales 8 randomState 3; do i = 1 to 2500; randomState = round(rand('gaussian',3,1)+0.5); if randomState in (1,2,3,4,5) then do; ( ) select(randomState); when(1) state='TN'; when(2) state='AL'; when(3) state= GA ; state='GA'; when(4) state='FL'; when(5) state='MS'; end; sales = int(rand('gaussian',1000000,500000)); output work.sales; end; end; run;
  • 5. Data Set Option or Statement data work.highSales; set work.sales (where=(sales>1500000)); run; data work highSales; work.highSales; set work.sales; where sales>1500000; run; proc means data=work.sales; where sales>1500000; run; ;
  • 6. Data Set Option or Statement data work.lowSales; set work.sales (where=(sales<0)); run; data work lowSales; work.lowSales; set work.sales; where sales<0; run; proc means data=work.sales (where=(sales<0)); run;
  • 7. Multiple Comparisons data work.highFloridaSales; set work.sales (where=(sales>1500000 and state = 'FL')); run; data work highFloridaSales; work.highFloridaSales; set work.sales; where sales>1500000 and state = 'FL'; run; proc freq data=work.sales; tables state; where sales>1500000 and state = 'FL'; ; run;
  • 8. SAS Functions data work.highFloridaSales; set work.sales (where=(sales>1500000 and substr(state,1,1) = 'F')); run; data work highFloridaSales; work.highFloridaSales; set work.sales; where sales>1500000 and substr(state,1,1) = 'F'; run; proc means data=work.sales; where sales>1500000 and substr(state,1,1) = 'F'; run; ;
  • 9. Comparison Operators Priority Order of Symbols Mnemonic Evaluation Equivalent Group I right to left ** + - ˆ¬~ NOT >< MIN <> MAX http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000780367.htm
  • 10. Comparison Operators Priority Order of Symbols Mnemonic Evaluation Equivalent Group II left to right * / Group left to right + III - Group left to right || ¦¦ !! IV http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000780367.htm
  • 11. Comparison Operators Priority Order of Symbols Mnemonic Evaluation Equivalent Group left to right < LT V <= LE = EQ ¬= NE >= GE > GT IN http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000780367.htm
  • 12. Comparison Operators Priority Order of Symbols Mnemonic Evaluation Equivalent Group left to right & AND VI Group left to right |¦! OR VII http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000780367.htm
  • 13. Comparison Operators data work.extremeNonGeorgia; set work.sales (where=((sales<0 | sales>1500000) and state in ('TN','AL','FL','MS'))); run; data work.extremeNonGeorgia; set work.sales; where (sales<0 | sales>1500000) and state in ('TN','AL','FL','MS'); run; data work.extremeNonGeorgia; set work.sales; ; where ^ (0 <= sales <= 1500000) & state ne 'GA'; run; http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
  • 14. “Between And” Between And data work.boundedNonGeorgia; set work.sales (where=((sales between 1000000 and 1500000) & state in ('TN','AL','FL','MS'))); run; data work.boundedNonGeorgia; set work.sales; where (sales between 1000000 and 1500000) & state in ('TN','AL','FL','MS'); t t i ('TN' 'AL' 'FL' 'MS') run; http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
  • 15. Contains ? data work.LStates; set work.sales (where=(state contains 'L')); run; data work LStates; work.LStates; set work.sales; where state contains 'L'; run; data work.LStates; set work.sales; where state ? 'L'; ; run; http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
  • 16. Is Null/Is Missing data work.nullStates; set work.sales (where=(state is null)); run; data work.missingStates; se o sa es (where=(state s ss g)); set work.sales ( e e (s a e is missing)); run; data work.nullSales; set work.sales; work sales; where sales is missing; run; data work.nonNullSales; set work.sales; where sales is not missing; run; http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
  • 17. Like data work.likeL; set work.sales (where=(state like '%L')); work sales run; data work.likeL; set work.sales (where=(state like quot;%Lquot;)); run; data work likeL; work.likeL; set work.sales (where=(state like quot;%%Lquot;)); run; data work.notLikeG; set work.sales; where state not like 'G_'; run; http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
  • 18. Sounds Like (Soundex) data work.soundsLikeFill; set work.sales (where=(state =* 'fill')); run; data work notSoundsLikeTin; work.notSoundsLikeTin; set work.sales; where state not =* 'tin'; run; http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
  • 19. “Same And” Same And data work.boundedNonGeorgia; set work.sales (where=((sales between 1000000 and 1500000) & state in ('TN','AL','FL','MS'))); run; data work.boundedNonGeorgia; set work.sales; where (sales between 1000000 and 1500000); where same and state i ('TN' 'AL' 'FL' 'MS') h d t t in ('TN','AL','FL','MS'); run; data work.boundedNonGeorgia; g ; set work.sales; where same and (sales between 1000000 and 1500000); where same and state in ('TN','AL','FL','MS'); run; http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000999255.htm
  • 20. WHERE vs. Subsetting IF vs Task Method Make the selection in a procedure without using a WHERE expression preceding DATA step Take advantage of the efficiency available with an indexed WHERE expression data set Use one of a group of special operators, such as WHERE expression BETWEEN-AND, CONTAINS, IS MISSING or IS NULL, LIKE, SAME-AND, and Sounds-Like B th l ti thi th th i bl l b tti Base the selection on anything other than a variable value subsetting IF that already exists in a SAS data set. For example, you can select a value that is read from raw data, or a value that is calculated or assigned during the course of the DATA step f th t Make the selection at some point during a DATA step subsetting IF rather than at the beginning Execute the selection conditionally subsetting IF http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a001000521.htm
  • 21. Intensive Dataset Generation %macro OurCentury(); %local year interest; y ; %do year = 2001 %to 2100; %let interest = %sysfunc(compound(1,.,0.05,%eval(&year.-2001))); data work.sales&year. (drop=i randomState index=(state sales)); length state $2 stateName $20 sales 8 randomState 3; g ; do i = 1 to 2500; randomState = round(56*rand('uniform')+0.5); if randomState <= 56 and randomState not in (3,7,14,43,52) then do; state = fipstate(randomState); p ( ) stateName = fipnameL(randomState); sales = int(rand('gaussian',1000000*&interest.,500000*&interest.)); output work.sales&year.; end; end; run; %end; %mend OurCentury; y %OurCentury;
  • 22. Year/State Datasets %macro SalesByYearState(); %local year stateCode state; %do year = 2001 %to 2100; %do stateCode = 1 %to 56; %if &stateCode ne 3 & &stateCode ne 7 & &stateCode. ne 14 & &stateCode. &stateCode. &stateCode &stateCode. ne 43 & &stateCode. ne 52 %then %do; %let state = %sysfunc(fipstate(&stateCode.)); data work.sales&year.&state.; set work.sales&year.; t k l & where state = quot;&state.quot;; run; %end; ; %end; %end; %mend SalesByYearState; %SalesByYearState;
  • 23. Year/State High Sales Datasets %macro HighSalesByYearState(); %local year stateCode state interest keepDataset; %do year = 2001 %to 2100; %let interest = %sysfunc(compound(1,.,0.05,%eval(&year.-2001))); %do stateCode = 1 %to 56; %if &stateCode. ne 3 & &stateCode. ne 7 & &stateCode. ne 14 & &stateCode. ne 43 & &stateCode. ne 52 %then %do; %let state = %sysfunc(fipstate(&stateCode.)); %let keepDataset = 0; data work.sales&year.&state.high; set work.sales&year.; where state = quot;&state.quot; and sales > 2000000*&i t h t t quot;& t t quot; d l 2000000*&interest.; t call symput('keepDataset',left('1')); run; %if not(&keepDataset.) %then %do; p proc datasets lib=work nolist; delete sales&year.&state.high; run; quit; %end; %end; %end; %end; %mend HighSalesByYearState; %HighSalesByYearState;
  • 24. Conclusion • The WHERE expression allows for efficient observation processing in the DATA step and the PROC statements • The SAS System Documentation provides specific details on the syntax • Using macros increases the processing power of WHERE expressions f i
  • 25. Contact Information • Mark Tabladillo MarkTab Consulting http://www.marktab.com/ http://www marktab com/