<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to do multiple if statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837347#M331062</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am new to sas EG so unsure how to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write a small bit of code within my proc sql that takes a column of phone numbers and creates a new flag column. I want the new column to produce a Y when the phone number is: not empty, 11 digits long, only digits and not equal to '11111111111' and a 'N' otherwise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2022 10:01:53 GMT</pubDate>
    <dc:creator>sas_user409</dc:creator>
    <dc:date>2022-10-07T10:01:53Z</dc:date>
    <item>
      <title>How to do multiple if statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837347#M331062</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am new to sas EG so unsure how to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write a small bit of code within my proc sql that takes a column of phone numbers and creates a new flag column. I want the new column to produce a Y when the phone number is: not empty, 11 digits long, only digits and not equal to '11111111111' and a 'N' otherwise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 10:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837347#M331062</guid>
      <dc:creator>sas_user409</dc:creator>
      <dc:date>2022-10-07T10:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple if statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837352#M331065</link>
      <description>&lt;P&gt;In SQL, you need CASE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  have.*,
  case
    when 
      length(have.phone) = 11 and notdigit(compress(have.phone," ")) = 0
      and have.phone ne "11111111111"
    then 1
    else 0
  end as flag
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it is shorter in a DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if
  length(phone) = 11 and notdigit(compress(phone," ")) = 0
  and phone ne "11111111111"
then flag = 1;
else flag = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I used numerical 1 and 0 because these can immediately be used as Boolean values later in the code.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 11:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837352#M331065</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-07T11:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple if statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837378#M331079</link>
      <description>Thanks so much for your help!</description>
      <pubDate>Fri, 07 Oct 2022 13:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837378#M331079</guid>
      <dc:creator>sas_user409</dc:creator>
      <dc:date>2022-10-07T13:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple if statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837388#M331084</link>
      <description>I also have a case statement for email column:&lt;BR /&gt;case&lt;BR /&gt;when&lt;BR /&gt;email is not missing&lt;BR /&gt;then 1&lt;BR /&gt;else 0&lt;BR /&gt;end as flag&lt;BR /&gt;&lt;BR /&gt;could you please tell me how would I also include to say when email does not contain '@' then flag it as 0</description>
      <pubDate>Fri, 07 Oct 2022 13:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837388#M331084</guid>
      <dc:creator>sas_user409</dc:creator>
      <dc:date>2022-10-07T13:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to do multiple if statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837402#M331092</link>
      <description>Use the INDEXC or FINDC function to detect a single character in a string.</description>
      <pubDate>Fri, 07 Oct 2022 13:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-multiple-if-statements/m-p/837402#M331092</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-07T13:50:01Z</dc:date>
    </item>
  </channel>
</rss>

