<?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: ISIN code convert from datastep to sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230144#M54456</link>
    <description>&lt;P&gt;Why do you want to do it in SQL?&lt;/P&gt;&lt;P&gt;Tthe data step works, no?&lt;/P&gt;</description>
    <pubDate>Thu, 15 Oct 2015 19:38:39 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2015-10-15T19:38:39Z</dc:date>
    <item>
      <title>ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230129#M54453</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;recently I wrote a programming in DATASTEP but i want to convert in proc SQL which I am not familiar with . can any one translate the code..&lt;/FONT&gt;.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%macro ISINVERIFICATION(infile=,isinfield=);&lt;/STRONG&gt; &lt;BR /&gt;DATA outfile; &lt;BR /&gt;SET &amp;amp;infile; &lt;BR /&gt;RTOTAL=0;TOTAL=0; length x $25;&lt;BR /&gt;DO J = 1 TO 11;&lt;BR /&gt;k=rank(upcase(substr(&amp;amp;isinfield,J,1))); &lt;BR /&gt;IF k GE 65 and k LE 95 then k=k-55; &lt;BR /&gt;IF k GE 48 and k LE 57 then k=k-48; &lt;BR /&gt;x=cats(x,k);&lt;BR /&gt;if K &amp;gt;= 10 then cnt=2; else if K &amp;lt; 10 then cnt=1; &lt;BR /&gt;RTOTAL=RTOTAL+cnt;&lt;BR /&gt;END; &lt;BR /&gt;do j=1 to RTOTAL;&lt;BR /&gt;y=substr(x,J,1); &lt;BR /&gt;if mod(RTOTAL,2)=0 then if mod(j,2)=0 then y=y*2;&lt;BR /&gt;if mod(RTOTAL,2)^=0 then if mod(j,2)^=0 then y=y*2;&lt;BR /&gt;TOTAL=TOTAL + int(y/10) + MOD(y,10);&lt;BR /&gt;if mod(Total + substr(&amp;amp;isinfield,12,1),10) = 0 then isinflag = 'yes'; else isinflag = 'no';&lt;BR /&gt;end;&lt;BR /&gt; DROP J x y cnt rtotal total k ; &lt;BR /&gt;RUN;&lt;BR /&gt;&lt;STRONG&gt;%mend;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;logic for above programming:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;APPLE: ISIN &lt;STRONG&gt;US0378331005&lt;/STRONG&gt;, expanded from &lt;STRONG&gt;CUSIP&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;037833100&lt;/STRONG&gt; The main body of the ISIN is the original CUSIP, assigned in the 1970s. The country code "US" has been added on the front, and an additional check digit at the end. The country code indicates the country of issue. The check digit is calculated in this way.&lt;/P&gt;
&lt;P&gt;Convert any letters to numbers:&lt;/P&gt;
&lt;P&gt;U = 30, S = 28. US037833100 -&amp;gt; 3028037833100.&lt;/P&gt;
&lt;P&gt;Collect odd and even characters:&lt;/P&gt;
&lt;P&gt;3028037833100 = (3, 2, 0, 7, 3, 1, 0), (0, 8, 3, 8, 3, 0)&lt;/P&gt;
&lt;P&gt;Multiply the group containing the rightmost character (which is the &lt;STRONG&gt;FIRST&lt;/STRONG&gt; group) by 2:&lt;/P&gt;
&lt;P&gt;(6, 4, 0, 14, 6, 2, 0)&lt;/P&gt;
&lt;P&gt;Add up the individual digits:&lt;/P&gt;
&lt;P&gt;(6 + 4 + 0 + (1 + 4) + 6 + 2 + 0) + (0 + 8 + 3 + 8 + 3 + 0) = 45&lt;/P&gt;
&lt;P&gt;Take the 10s modulus of the sum:&lt;/P&gt;
&lt;P&gt;45 mod 10 = 5&lt;/P&gt;
&lt;P&gt;Subtract from 10:&lt;/P&gt;
&lt;P&gt;10 - 5 = 5&lt;/P&gt;
&lt;P&gt;Take the 10s modulus of the result (this final step is important in the instance where the modulus of the sum is 0, as the resulting check digit would be 10).&lt;/P&gt;
&lt;P&gt;5 mod 10 = 5&lt;/P&gt;
&lt;P&gt;So the ISIN check digit is five.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;OUTPUT: &amp;nbsp;&lt;/STRONG&gt;It checks a ISIN number created a FLAG which shows pass,fail and blank&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;
&lt;P&gt;&lt;STRONG&gt;It will be very helpful and your help is much appreciated&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 17:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230129#M54453</guid>
      <dc:creator>siddharthpeesary</dc:creator>
      <dc:date>2015-10-15T17:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230144#M54456</link>
      <description>&lt;P&gt;Why do you want to do it in SQL?&lt;/P&gt;&lt;P&gt;Tthe data step works, no?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 19:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230144#M54456</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-10-15T19:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230178#M54462</link>
      <description>&lt;P&gt;because I want to keep SQL(ISIN) in hadoop (contains sas loader) in data validation rule engine.. where it does not accepts data step function.&lt;/P&gt;
&lt;P&gt;so i want to convert in sql &amp;nbsp;for sure.&lt;/P&gt;
&lt;P&gt;My data step works perfect..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 21:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230178#M54462</guid>
      <dc:creator>siddharthpeesary</dc:creator>
      <dc:date>2015-10-15T21:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230197#M54463</link>
      <description>&lt;P&gt;Can you please provide some mock-up data (created using a data step) which works with your macro. This will allow us to actually test what we might propose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be aware that only a sub-set of SAS functions can be passed to Hadoop (Hive) for processing.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/68028/HTML/default/viewer.htm#p010gv8z4k5kvin1ombbmqdpumhd.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/acreldb/68028/HTML/default/viewer.htm#p010gv8z4k5kvin1ombbmqdpumhd.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because the MOD() function is not in the list I would assume that pass-through SQL will be required. That will make it a bit harder for most of us as one needs actual access to Hadoop in order to test correctness of the syntax.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 23:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230197#M54463</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-15T23:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230204#M54464</link>
      <description>&lt;P&gt;Thanks so much.I can do the part for hadoop .. my main objective is to write it in proc sql.&lt;/P&gt;
&lt;P&gt;please see my attached files&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro importdata(infile=,outfile=,type=,get=,filter=);
proc import
datafile=&amp;amp;infile
dbms=&amp;amp;type
out=&amp;amp;outfile 
 replace;
 getnames=&amp;amp;get;
&amp;amp;filter;
run;
%mend importdata;&lt;BR /&gt;/*please run the sas programming then you will get out put &lt;BR /&gt; please let me know if there are any mis-understandings*/&lt;BR /&gt;
%importdata(infile='(PATHNAME)\input_isin.xlsx',outfile=test_isin,type=XLSX,get=YES,filter=guessingrows=10000);



%macro ISINVERIFICATION(infile=,isinfield=); 
DATA out_isin; 
SET &amp;amp;infile; 
RTOTAL=0;TOTAL=0; length x $25;
DO J = 1 TO 11;
k=rank(upcase(substr(&amp;amp;isinfield,J,1))); 
IF k GE 65 and k LE 95 then k=k-55; 
IF k GE 48 and k LE 57 then k=k-48; 
x=cats(x,k);
if K &amp;gt;= 10 then cnt=2; else if K &amp;lt; 10 then cnt=1; 
RTOTAL=RTOTAL+cnt;
END; 
do j=1 to RTOTAL;
y=substr(x,J,1); 
if mod(RTOTAL,2)=0 then if mod(j,2)=0 then y=y*2;
if mod(RTOTAL,2)^=0 then if mod(j,2)^=0 then y=y*2;
TOTAL=TOTAL + int(y/10) + MOD(y,10);
if mod(Total + substr(&amp;amp;isinfield,12,1),10) = 0 then isinflag = 'yes'; else isinflag = 'no';
end;
  DROP J x y cnt rtotal total k ; 
RUN;
%mend;

%ISINVERIFICATION(infile=test_isin,isinfield=ISIN); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 00:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230204#M54464</guid>
      <dc:creator>siddharthpeesary</dc:creator>
      <dc:date>2015-10-16T00:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230206#M54465</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/47212"&gt;@siddharthpeesary﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;O.K., now I understand what you're doing. I wouldn't know how to convert your data step&amp;nbsp;into reasonable standard SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe what you need to do is implement your check as a user defined function directly in Hadoop which you then can call via a pass-through SQL out of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below example demonstrates the concept by creating a SAS function. I lack the Hadoop experience to give you more guidance but searching through the&amp;nbsp;Internet I believe this is a possible approach.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.funcs.check_isin;
  function check_isin(isin $) $;
    RTOTAL=0;
    TOTAL=0;
    length x $25 y 8 isinflag $3;
    DO J = 1 TO 11;
      k=rank(upcase(substr(ISIN,J,1)));
      IF k GE 65 and k LE 95 then
        k=k-55;
      IF k GE 48 and k LE 57 then
        k=k-48;
      x=cats(x,k);
      if K &amp;gt;= 10 then
        cnt=2;
      else if K &amp;lt; 10 then
        cnt=1;
      RTOTAL=RTOTAL+cnt;
    END;

    do j=1 to RTOTAL;
      y=substr(x,J,1);
      if mod(RTOTAL,2)=0 then if mod(j,2)=0   then y=y*2;
      if mod(RTOTAL,2)^=0 then if mod(j,2)^=0 then y=y*2;
      TOTAL=TOTAL + int(y/10) + MOD(y,10);
/*      if mod(Total + substr(ISIN,12,1),10) = 0 then*/
      digit=substrn(ISIN,12,1);
      if not findc(digit,'0123456789') then digit='0';
      if mod(Total +inputn(digit,8.),10) = 0 then
        isinflag = 'yes';
      else isinflag = 'no';
    end;

    return(isinflag);
  endsub;
run;

quit;

options cmplib=work.funcs;

proc sql;
  create table want as
  select 
    isin, 
    check_isin(isin) as flag
  from test_isin
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Oct 2015 02:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230206#M54465</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-16T02:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230210#M54466</link>
      <description>&lt;P&gt;These FCMP can be used in hadoop sas??&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if it is.... the logic inside the function is in datastep..it can be executed in hadoop(sas loader)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 03:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230210#M54466</guid>
      <dc:creator>siddharthpeesary</dc:creator>
      <dc:date>2015-10-16T03:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230231#M54470</link>
      <description>&lt;P&gt;Hmmm... This was actually only to demonstrate the concept. I was more thinking of creating a UDF without SAS tools and then use this UDF within pass-through SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&amp;nbsp;&lt;A href="https://cwiki.apache.org/confluence/display/Hive/HivePlugins" target="_blank"&gt;https://cwiki.apache.org/confluence/display/Hive/HivePlugins&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 05:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230231#M54470</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-16T05:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230301#M54475</link>
      <description>&lt;P&gt;So you are saying we have to write the code using &lt;STRONG&gt;HIVE functions&lt;/STRONG&gt;&amp;nbsp;to create UDF or we can pull sas functions to it?&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;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 14:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230301#M54475</guid>
      <dc:creator>siddharthpeesary</dc:creator>
      <dc:date>2015-10-16T14:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: ISIN code convert from datastep to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230384#M54488</link>
      <description>&lt;P&gt;I'm just throwing ideas here! I don't have enough real experience working with Hadoop out of SAS to do something else.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, my thinking is to write a HIVE function and then to call this function out of pass-through SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is the&amp;nbsp;SAS In-Database Code Accelerator for Hadoop (I believe needs a separate licence):&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/indbug/68170/HTML/default/viewer.htm#n13tmaloxv64n3n1ixvrx120b6oh.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/indbug/68170/HTML/default/viewer.htm#n13tmaloxv64n3n1ixvrx120b6oh.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Never used it but it appears it would allow you to publish SAS DS2 programs to Hadoop. That could be another option for you.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/proc/67916/HTML/default/viewer.htm#n0ox2hnyx7twb2n13200g5hqqsmy.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/proc/67916/HTML/default/viewer.htm#n0ox2hnyx7twb2n13200g5hqqsmy.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/ds2ref/68052/HTML/default/viewer.htm#titlepage.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/ds2ref/68052/HTML/default/viewer.htm#titlepage.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DS2 is a new language (also with a lot of syntactical similarities to Base SAS) and it will take you a bit to skill-up with it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 22:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/ISIN-code-convert-from-datastep-to-sql/m-p/230384#M54488</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-16T22:20:20Z</dc:date>
    </item>
  </channel>
</rss>

