<?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 Re: How do I validate a customer name field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907532#M358233</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp; thank you for sharing. Unfortunately, we don't have Viya. wish I did!&lt;/P&gt;</description>
    <pubDate>Tue, 12 Dec 2023 13:35:16 GMT</pubDate>
    <dc:creator>JoeJ</dc:creator>
    <dc:date>2023-12-12T13:35:16Z</dc:date>
    <item>
      <title>How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/906991#M358091</link>
      <description>&lt;P&gt;Hi I am looking to validate a customer name field. I need to only include values that contain the following information:&lt;/P&gt;&lt;P&gt;Acceptable customer name example formats:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;last name, first name&lt;/P&gt;&lt;P&gt;Doe, Jane&lt;/P&gt;&lt;P&gt;Doe, John&lt;/P&gt;&lt;P&gt;Anthony-Smith, Jim&lt;/P&gt;&lt;P&gt;Requirements:&lt;/P&gt;&lt;P&gt;&amp;nbsp;- customer name is doesn't contain numbers or special characters. There are cases where the name is hyphenated, which is acceptable.&amp;nbsp; &amp;nbsp;I was trying this code but not able to get it to work -&amp;nbsp;&lt;/P&gt;&lt;P&gt;select&amp;nbsp;upcase(strip(compbl(COMPRESS(COMPRESS(cust_name, ""~!@#$%^&amp;amp;*()-_=+\|[]{};:'‘’,.&amp;lt;&amp;gt;?/""),'""""')))) from my_data;&lt;/P&gt;&lt;P&gt;- Need to confirm that the length for the last and first name have a min length of 1 byte each. I am able to determine the length of the field, not sure how to validate the length prior to the comma and preceding the comma.&amp;nbsp;&lt;/P&gt;&lt;P&gt;select&amp;nbsp;LENGTH(CUST_NAME) AS LEN FROM MY_DATA;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 15:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/906991#M358091</guid>
      <dc:creator>JoeJ</dc:creator>
      <dc:date>2023-12-08T15:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907002#M358093</link>
      <description>&lt;P&gt;Why COMPRESS?&amp;nbsp; Are you trying to VALIDATE the value or FIX the value?&lt;/P&gt;
&lt;P&gt;If you want to check for invalid characters you could use INDEXC() function.&lt;/P&gt;
&lt;P&gt;If you want to check that only VALID characters appear then you could use the VERIFY() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should count how many commas.&amp;nbsp; There should be only 1.&lt;/P&gt;
&lt;P&gt;Once you know there is only one comma you can use SCAN() to pull out the first and last name parts so you can test their length.&amp;nbsp; length(scan(cust_name,1,',')) or length(scan(cust_name,2,','))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 16:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907002#M358093</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-08T16:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907007#M358095</link>
      <description>&lt;P&gt;The command I posted with compress was just me experimenting. I wasn't sure that was the correct option.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the cust name field has junk data in it like invalid characters and numbers. I am not familiar with the functions you listed,&amp;nbsp;&lt;SPAN&gt;INDEXC() or&amp;nbsp;VERIFY()&amp;nbsp;. I will research those options.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Correct, there should only be 1 comma. I will try both options to see what result I get.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for the quick response.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Joe&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 16:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907007#M358095</guid>
      <dc:creator>JoeJ</dc:creator>
      <dc:date>2023-12-08T16:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907014#M358096</link>
      <description>&lt;P&gt;In my not so humble opinion, I would say this indicates to an incorrect reading of the data when brought into SAS. First and last names should be separate variables. These combined name fields are right up there with 1960 data processing standards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have spent way to much time "fixing" name fields that have stuff combined in one variable to do so if I can possibly avoid it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note on posting code, really a good idea to post into either a text or code box opened on the forum with the &amp;lt;/&amp;gt; or "running man" icons that appear above the message window. The message window here does reformat pasted text which may lead to the appearance of your Compress function call appearing to have unbalanced quotes and parentheses when I copy it to my editor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure your data does not contain any names like "Van Dyke" or "Le Blanc" where there are spaces in the last name? Will that have any impact on your processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 16:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907014#M358096</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-08T16:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907035#M358100</link>
      <description>&lt;P&gt;I agree with you 100% that the the name should be broken up into 2 separate fields. Unfortunately I don't have control over how the table was built.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Noted on posting code. It's possible that I messed up the syntax when coding so there could be missing values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes it is possible for the data to be formatted&amp;nbsp;&lt;SPAN&gt;like "Van **bleep**" or "Le Blanc". Is there a different way to check for that?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 17:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907035#M358100</guid>
      <dc:creator>JoeJ</dc:creator>
      <dc:date>2023-12-08T17:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907068#M358103</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/365344"&gt;@JoeJ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes it is possible for the data to be formatted&amp;nbsp;&lt;SPAN&gt;like "Van **bleep**" or "Le Blanc". Is there a different way to check for that?&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's why I copied your function call to my editor. One of the most likely characters to get "reformatted" is a space character. If you don't compress them away or Strip in the wrong order then the Scan that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; suggests should have no problem as it only used the comma to delimit values instead of the default behavior that would include spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless there is a very good reason not to, i.e. the boss says not to, I would likely use this step as the time to create separate first and last name variables using scan (after defining lengths long enough to hold the longest every expected name value for the variables).&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 17:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907068#M358103</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-08T17:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907074#M358105</link>
      <description>&lt;P&gt;If you don't mind could you show me an example of what you are referring too? I am not clear as to what you are saying.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 17:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907074#M358105</guid>
      <dc:creator>JoeJ</dc:creator>
      <dc:date>2023-12-08T17:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907088#M358106</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input cust_name $30.;
cards;
Doe,Jane
Doe, John
Anthony-Smith, Jim
James,Hen3ry
Mary Lou Jones
Jim,Bob,Tucker
;

data want;
  set have;
  length fname lname $30 ;
  valid=1;
  if count(cust_name,',') ne 1 then do;
    put 'WARNING: Wrong number of commas. ' cust_name=;
    valid=0;
  end;
  if compress(cust_name,'-,','a') ne ' ' then do;
    put 'WARNING: Invalid character. ' cust_name=;
    valid=0;
  end;
  lname=scan(cust_name,1,',');
  fname=scan(cust_name,2,',');
  if valid then cust_name=catx(', ',lname,fname);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1702059553147.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91082i7F344B79C37E03EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1702059553147.png" alt="Tom_0-1702059553147.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 18:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907088#M358106</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-08T18:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907095#M358107</link>
      <description>&lt;P&gt;Thank you I will try that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 18:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907095#M358107</guid>
      <dc:creator>JoeJ</dc:creator>
      <dc:date>2023-12-08T18:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907180#M358138</link>
      <description>&lt;P&gt;On top of what others already wrote: If you really want to clean-up your data then ideally use SAS' data quality functions (if licensed). Here an &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Coding-for-Data-Quality-in-SAS-Viya-Part-1-Fundamentals/ta-p/890611" target="_self"&gt;article for Viya&lt;/A&gt; but very similar (or even the same) code should already work in SAS9.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2023 03:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907180#M358138</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-10T03:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907531#M358232</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; I have been working with your example. It's working well. Just have a few questions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;- Where does the output from the put statement get written?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;- I didn't specify this in the beginning but I am running this against 38mm records. Is this the most efficient way to process this data?&amp;nbsp;&lt;/P&gt;&lt;P&gt;- In this statement&amp;nbsp;&amp;nbsp;if compress(cust_name,'-,','a') ne ' ' will this identify records that have values other than alpha characters like numeric values?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Joe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 13:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907531#M358232</guid>
      <dc:creator>JoeJ</dc:creator>
      <dc:date>2023-12-12T13:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907532#M358233</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp; thank you for sharing. Unfortunately, we don't have Viya. wish I did!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 13:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907532#M358233</guid>
      <dc:creator>JoeJ</dc:creator>
      <dc:date>2023-12-12T13:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907559#M358243</link>
      <description>&lt;P&gt;PUT statements write to the current output file.&amp;nbsp; If no FILE statement has been run then that is the SAS log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect to have more than a handful of bad records then don't write the warnings to the log.&amp;nbsp; Perhaps you could change the code to put the note into a character variable that you could review later.&amp;nbsp; For example by running a reporting step that list (or perhaps just summarizes) the types of bad values found.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 14:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907559#M358243</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-12T14:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907687#M358297</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; &amp;nbsp;Why would these records be flagged based on this code&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;if count(cust_nm,',') ne 1 then do;
    warning= 'WARNING: Wrong number of commas. ';
    valid=0;
  end;&lt;/PRE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CUST_NM&lt;/TD&gt;&lt;TD&gt;fname&lt;/TD&gt;&lt;TD&gt;lname&lt;/TD&gt;&lt;TD&gt;warning&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MARY FLOWERS&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;MARY FLOWERS&lt;/TD&gt;&lt;TD&gt;WARNING: Wrong number of commas.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;TRAVEL FIRST LLC&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;TRAVEL FIRST LLC&lt;/TD&gt;&lt;TD&gt;WARNING: Wrong number of commas.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 12 Dec 2023 23:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907687#M358297</guid>
      <dc:creator>JoeJ</dc:creator>
      <dc:date>2023-12-12T23:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907688#M358298</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/365344"&gt;@JoeJ&lt;/a&gt;&amp;nbsp; - SAS Data Quality is also available in SAS 9.4, but if you don't have it there would be an extra cost in licensing it.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 23:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907688#M358298</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-12-12T23:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I validate a customer name field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907689#M358299</link>
      <description>&lt;P&gt;Huh?&lt;/P&gt;
&lt;P&gt;They don't have a comma between the first and last name.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 00:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-validate-a-customer-name-field/m-p/907689#M358299</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-13T00:02:42Z</dc:date>
    </item>
  </channel>
</rss>

