<?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: Validating an ID Number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613389#M179121</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, of course. It is always good practice to avoid unnecessary functions, and the substr function is "overdoing things". I often do that, and&amp;nbsp;I checked a couple of programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found this construct: &lt;STRONG&gt;ThisSSN = strip(scan(RelationList,i,','))&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;-&amp;nbsp;&lt;/STRONG&gt;I know that&amp;nbsp;RelationList is always a list of social security numbers, They will never contain embedded blanks or other default delimiters, so &lt;U&gt;in this case&lt;/U&gt; scanning by belimiter and stripping is unnecessary.&amp;nbsp;&lt;STRONG&gt;ThisSSN = scan(RelationList,i)&amp;nbsp;&lt;/STRONG&gt;would give the same result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We all have a set of ingrown habits, when it comes to coding, and&amp;nbsp;I wonder how much effort should be put in the final optimization of a program. it certainly makes the code more readable, but does it matter in terms of computing time?&amp;nbsp;I made a test just for fun to see the impact of removing the substring function in the valid-check, and it does make a difference, about 10%:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;45    data _null_;
46        set have;
47        *Valid = (input(SA_ID,??yymmdd6.) ne .);
48        Valid = (input(substr(SA_ID,1,6),??yymmdd6.) ne .);
49    run;

NOTE: There were 50000000 observations read from the data set WORK.HAVE.
NOTE: DATA statement used (Total process time):
      real time           6.53 seconds
      cpu time            6.54 seconds


50    data _null_;
51        set have;
52        Valid = (input(SA_ID,??yymmdd6.) ne .);
53        *Valid = (input(substr(SA_ID,1,6),??yymmdd6.) ne .);
54    run;

NOTE: There were 50000000 observations read from the data set WORK.HAVE.
NOTE: DATA statement used (Total process time):
      real time           6.06 seconds
      cpu time            5.97 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I wish you a good weekend&lt;/P&gt;
&lt;P&gt;Erik&lt;/P&gt;</description>
    <pubDate>Sat, 21 Dec 2019 11:32:35 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2019-12-21T11:32:35Z</dc:date>
    <item>
      <title>Validating an ID Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613196#M179059</link>
      <description>&lt;P&gt;Good Day&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please assist with a code to validate the first 6 digit of an SA ID Number(YYMMDD).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 08:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613196#M179059</guid>
      <dc:creator>NOMBUH</dc:creator>
      <dc:date>2019-12-20T08:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Validating an ID Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613202#M179062</link>
      <description>&lt;P&gt;I don't know what a "SA ID Number" is, so please post an excerpt of the data you have and what you except as result.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 09:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613202#M179062</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-12-20T09:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Validating an ID Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613203#M179063</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270139"&gt;@NOMBUH&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you refer to the S&lt;SPAN&gt;outh African ID number?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If yes, as the first 6 digits&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;(YYMMDD) are based on the date of birth, which level of validation do you want?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- exact date: do you have a&amp;nbsp;dataset containing the date of birth of someone and its SA ID number?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- "plausible" date: do you want to test if YMMDD could be a date? (eg. MM -&amp;gt; 01 to 12), ...?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide more details.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 09:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613203#M179063</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-20T09:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Validating an ID Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613285#M179094</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270139"&gt;@NOMBUH&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simple way to check for a valid date is to see if the string can be converted to a valid sas date with an input function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note ?? in the following example. It is a format modifier, so the input function does not treat an invalid date as an error, but returns a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	SA_ID = '3333331234'; output;
	SA_ID = '1313131234'; output;
	SA_ID = '1212121234'; output;
	SA_ID = '1901271234'; output;	
run;

data want; set have;
	Valid = (input(substr(SA_ID,1,6),??yymmdd6.) ne .);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="datevalidation.gif" style="width: 243px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34975i0C45560C3EDD44D6/image-size/large?v=v2&amp;amp;px=999" role="button" title="datevalidation.gif" alt="datevalidation.gif" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 17:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613285#M179094</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-12-20T17:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Validating an ID Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613345#M179108</link>
      <description>&lt;P&gt;The data step code could be reduced to:&lt;/P&gt;
&lt;PRE&gt;data want; &lt;BR /&gt;	set have;
	Valid = (input(SA_ID,??yymmdd6.) ne .);
run;&lt;/PRE&gt;
&lt;P&gt;A specified length on the informat only reads that many characters so the substr shouldn't be needed.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 20:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613345#M179108</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-20T20:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Validating an ID Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613389#M179121</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, of course. It is always good practice to avoid unnecessary functions, and the substr function is "overdoing things". I often do that, and&amp;nbsp;I checked a couple of programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found this construct: &lt;STRONG&gt;ThisSSN = strip(scan(RelationList,i,','))&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;-&amp;nbsp;&lt;/STRONG&gt;I know that&amp;nbsp;RelationList is always a list of social security numbers, They will never contain embedded blanks or other default delimiters, so &lt;U&gt;in this case&lt;/U&gt; scanning by belimiter and stripping is unnecessary.&amp;nbsp;&lt;STRONG&gt;ThisSSN = scan(RelationList,i)&amp;nbsp;&lt;/STRONG&gt;would give the same result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We all have a set of ingrown habits, when it comes to coding, and&amp;nbsp;I wonder how much effort should be put in the final optimization of a program. it certainly makes the code more readable, but does it matter in terms of computing time?&amp;nbsp;I made a test just for fun to see the impact of removing the substring function in the valid-check, and it does make a difference, about 10%:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;45    data _null_;
46        set have;
47        *Valid = (input(SA_ID,??yymmdd6.) ne .);
48        Valid = (input(substr(SA_ID,1,6),??yymmdd6.) ne .);
49    run;

NOTE: There were 50000000 observations read from the data set WORK.HAVE.
NOTE: DATA statement used (Total process time):
      real time           6.53 seconds
      cpu time            6.54 seconds


50    data _null_;
51        set have;
52        Valid = (input(SA_ID,??yymmdd6.) ne .);
53        *Valid = (input(substr(SA_ID,1,6),??yymmdd6.) ne .);
54    run;

NOTE: There were 50000000 observations read from the data set WORK.HAVE.
NOTE: DATA statement used (Total process time):
      real time           6.06 seconds
      cpu time            5.97 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I wish you a good weekend&lt;/P&gt;
&lt;P&gt;Erik&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 11:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validating-an-ID-Number/m-p/613389#M179121</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-12-21T11:32:35Z</dc:date>
    </item>
  </channel>
</rss>

