<?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 Substring and possible array testing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-possible-array-testing/m-p/726533#M225758</link>
    <description>&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;length borr_ph $10 co_borr_ph $10 alt_ph $10 ;&lt;BR /&gt;input borr_ph -- alt_ph;&lt;BR /&gt;datalines;&lt;BR /&gt;8042234314 0000000000 3334444444&lt;BR /&gt;0000000000 1111111111 9999999999&lt;BR /&gt;2132245566 1121111111 2321111111&lt;BR /&gt;1111114444 0000000000 1111111111&lt;BR /&gt;1112223333 8042342256 0000000000 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if substr(borr_ph,1,4) in('0000','1111','2222','3333','4444','9999') then no_borr_ph='Y';&lt;BR /&gt;if substr(co_borr_ph,1,4) in('0000','1111','2222','3333','4444','9999') then no_co_borr_ph='Y';&lt;BR /&gt;if substr(alt_ph,1,4) in('0000','1111','2222','3333','4444','9999') then no_alt_ph='Y';&lt;BR /&gt;if no_borr_ph ='Y' and no_co_borr_ph='Y' and no_alt_ph = 'Y' then No_Phone = 'Y';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used a substr analysis to try and identify phantom phone numbers (numbers that&lt;/P&gt;
&lt;P&gt;obviously are bogus)&amp;nbsp; I successfully flagged those with the phantom or non-phone number.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;My actual code has about &lt;STRONG&gt;20&lt;/STRONG&gt; different phone numbers.&amp;nbsp; Is there a way to apply some type&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;of array so I do not have to repeat the entire sequence of code as seen here.&lt;/P&gt;
&lt;P&gt;Note the reason I am using a sequence of first four numbers is because it is unlikely&lt;/P&gt;
&lt;P&gt;that a phone number begin with the same &lt;STRONG&gt;4&lt;/STRONG&gt; numbers consecutive&lt;/P&gt;</description>
    <pubDate>Mon, 15 Mar 2021 20:33:06 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2021-03-15T20:33:06Z</dc:date>
    <item>
      <title>Substring and possible array testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-possible-array-testing/m-p/726533#M225758</link>
      <description>&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;length borr_ph $10 co_borr_ph $10 alt_ph $10 ;&lt;BR /&gt;input borr_ph -- alt_ph;&lt;BR /&gt;datalines;&lt;BR /&gt;8042234314 0000000000 3334444444&lt;BR /&gt;0000000000 1111111111 9999999999&lt;BR /&gt;2132245566 1121111111 2321111111&lt;BR /&gt;1111114444 0000000000 1111111111&lt;BR /&gt;1112223333 8042342256 0000000000 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if substr(borr_ph,1,4) in('0000','1111','2222','3333','4444','9999') then no_borr_ph='Y';&lt;BR /&gt;if substr(co_borr_ph,1,4) in('0000','1111','2222','3333','4444','9999') then no_co_borr_ph='Y';&lt;BR /&gt;if substr(alt_ph,1,4) in('0000','1111','2222','3333','4444','9999') then no_alt_ph='Y';&lt;BR /&gt;if no_borr_ph ='Y' and no_co_borr_ph='Y' and no_alt_ph = 'Y' then No_Phone = 'Y';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used a substr analysis to try and identify phantom phone numbers (numbers that&lt;/P&gt;
&lt;P&gt;obviously are bogus)&amp;nbsp; I successfully flagged those with the phantom or non-phone number.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;My actual code has about &lt;STRONG&gt;20&lt;/STRONG&gt; different phone numbers.&amp;nbsp; Is there a way to apply some type&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;of array so I do not have to repeat the entire sequence of code as seen here.&lt;/P&gt;
&lt;P&gt;Note the reason I am using a sequence of first four numbers is because it is unlikely&lt;/P&gt;
&lt;P&gt;that a phone number begin with the same &lt;STRONG&gt;4&lt;/STRONG&gt; numbers consecutive&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 20:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-and-possible-array-testing/m-p/726533#M225758</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-03-15T20:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Substring and possible array testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-possible-array-testing/m-p/726541#M225762</link>
      <description>&lt;P&gt;Not sure exactly why you are testing 4 characters. If this is US and related phone numbers you have two section to check for 000- the first 3 are area code and next three are exchanges. I know from processing phone numbers I have seen invalid exchanges, like 000 when the area code was valid: 208-000-0000 for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array processing would take two arrays such as:&lt;/P&gt;
&lt;PRE&gt;data have;
   length borr_ph $10 co_borr_ph $10 alt_ph $10 ;
   input borr_ph -- alt_ph;
   array ph (*) borr_ph -- alt_ph;
   array np (3) no_borr_ph no_co_borr_ph no_alt_ph  ; 
   do i= 1 to dim(ph);
      np[i] = (substr(ph[i],1,4) in('0000','1111','2222','3333','4444','9999')  );
   end;
   drop i;
datalines;
8042234314 0000000000 3334444444
0000000000 1111111111 9999999999
2132245566 1121111111 2321111111
1111114444 0000000000 1111111111
1112223333 8042342256 0000000000
;&lt;/PRE&gt;
&lt;P&gt;I prefer numeric 1 (true)/0 (false) coded variables instead of 'Y' as there are more reporting options PLUS SAS will return a numeric 1/0 for comparisons. So cuts down on specific "Then var = 'Y';" type codes.&lt;/P&gt;
&lt;P&gt;For instance, if you need to know if ALL of the values are "true" instead of 3 (or 20) if var='y' and var2='y' .. you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No_phone = min(of np(*) );&lt;/P&gt;
&lt;P&gt;Since the NP array elements will be 0 or 1 if at least one of the values has a valid phone (assuming those checks worked correctly) then the Min value for the array will be 0. If all are not valid then the min is 1 , or the "not a phone".&lt;/P&gt;
&lt;P&gt;Notice that the " of arrayname(*) " syntax does not care at all about how many variables are in the array. So the length of the syntax doesn't change. Character variables take a bit more work, not much but some.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would suggest looking a bit more into proper numbers. US for example US &lt;STRONG&gt;phones&lt;/STRONG&gt; all use one single &lt;STRONG&gt;format&lt;/STRONG&gt;: (NXX) NXX-XXXX, where N is 2-9 and X is 0-9. So area code cannot start with 0 or 1, neither can exchange (the second 3 characters).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really must see a Y/N then a custom format for 1/0 coded values can do that.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 21:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-and-possible-array-testing/m-p/726541#M225762</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-15T21:14:08Z</dc:date>
    </item>
  </channel>
</rss>

