<?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 Need help with array lookups in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189108#M47784</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I need some guidance on a SAS program I am trying to code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table of 18,000&lt;BR /&gt;industry names and codes.&amp;nbsp; I want to load the data into a 2 dimensional&lt;BR /&gt;array of 2 columns X 18000 rows.&amp;nbsp; The first column of the array will be&lt;BR /&gt;industry name and the second column of the array will be industry code.&lt;/P&gt;&lt;OL style="list-style-type: decimal;"&gt;&lt;LI&gt;Then I want to sequentially read a file of company names, and check to see if any word in the company name&lt;BR /&gt;matches an industry name.&amp;nbsp; If it does I want to append the industry name&lt;BR /&gt;and number to the company name.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;For example:&amp;nbsp; Industry Name Table (18,000 rows)&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="99" style="border: 1px solid rgb(0, 0, 0); width: 835px; height: 36px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Industry Name&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Industry Code&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Electrical&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Plumbing&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Masonry&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;003&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Company name Input Table (1 field called company name):&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="49" style="border: 1px solid rgb(0, 0, 0); width: 473px; height: 44px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Company Name&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Steve's Plumbing&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Desired Output (3 fields: company name, industry name, industry code)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Company Na&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Industry Name&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Industry COde&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Steve's Plumbing&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Plumbing&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Electrical&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HELP!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Jun 2014 07:04:54 GMT</pubDate>
    <dc:creator>steveg1</dc:creator>
    <dc:date>2014-06-09T07:04:54Z</dc:date>
    <item>
      <title>Need help with array lookups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189108#M47784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I need some guidance on a SAS program I am trying to code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table of 18,000&lt;BR /&gt;industry names and codes.&amp;nbsp; I want to load the data into a 2 dimensional&lt;BR /&gt;array of 2 columns X 18000 rows.&amp;nbsp; The first column of the array will be&lt;BR /&gt;industry name and the second column of the array will be industry code.&lt;/P&gt;&lt;OL style="list-style-type: decimal;"&gt;&lt;LI&gt;Then I want to sequentially read a file of company names, and check to see if any word in the company name&lt;BR /&gt;matches an industry name.&amp;nbsp; If it does I want to append the industry name&lt;BR /&gt;and number to the company name.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;For example:&amp;nbsp; Industry Name Table (18,000 rows)&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="99" style="border: 1px solid rgb(0, 0, 0); width: 835px; height: 36px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Industry Name&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Industry Code&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Electrical&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Plumbing&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Masonry&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;003&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Company name Input Table (1 field called company name):&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="49" style="border: 1px solid rgb(0, 0, 0); width: 473px; height: 44px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Company Name&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Steve's Plumbing&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Desired Output (3 fields: company name, industry name, industry code)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Company Na&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Industry Name&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Industry COde&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Steve's Plumbing&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Plumbing&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Electrical&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HELP!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 07:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189108#M47784</guid>
      <dc:creator>steveg1</dc:creator>
      <dc:date>2014-06-09T07:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with array lookups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189109#M47785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Some code like below could eventually do the job. The second case I've added to the data might also demonstrate some of the issues you will have to solve when dealing with real data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data Industry;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover dsd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input Industry_Nm:$40. Industry_Cd:$6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Industry_Nm=propcase(Industry_Nm);&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Electrical,001&lt;/P&gt;&lt;P&gt;Plumbing,002&lt;/P&gt;&lt;P&gt;Masonry,003&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data Company_Name;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover dsd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input Company_Nm:$80.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Steve's Plumbing&lt;/P&gt;&lt;P&gt;The ELECTRICAL&amp;amp;PLUMBING Company&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 0 then set Industry;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dcl hash h(dataset:'Industry');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rc=h.defineKey('Industry_Nm');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rc=h.defineData(all:'yes');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rc=h.defineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call missing(Industry_Nm, Industry_Cd);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set Company_Name;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length _word $80;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _i=1 by 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _word=scan(Company_Nm,_i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if missing(_word) then leave;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _word=propcase(_word);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put _word;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if h.find(key:_word)=0 then leave;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 07:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189109#M47785</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-06-09T07:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with array lookups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189110#M47786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, you don't mention what your Industry data looks like, or what the file is you are reading in.&amp;nbsp; Therefore I will assume the data is as it looks above, and the file is Excel (note I have not tested this):&lt;/P&gt;&lt;P&gt;libname myexcel excel "an excel file.xls";&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COMPANY.NAME,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INDUSTRY.NAME,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INDUSTRY.CODE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MYEXCEL.'sheet1'n COMPANY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INDUSTRY_NAME_TABLE INDUSTRY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index(COMPANY.NAME,INDUSTRY.NAME)&amp;gt;0; /* Note you may want to upcase both, or you may not */&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 09:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189110#M47786</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-09T09:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with array lookups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189111#M47787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think Patrick's code is very good. and if your table is not large , you also can get it by SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data Industry;
&amp;nbsp; infile datalines truncover dsd;
&amp;nbsp; input Industry_Nm:$40. Industry_Cd:$6.;
&amp;nbsp; Industry_Nm=propcase(Industry_Nm);
&amp;nbsp; datalines;
Electrical,001
Plumbing,002
Masonry,003
;
run;
 
 
data Company_Name;
&amp;nbsp; infile datalines truncover dsd;
&amp;nbsp; input Company_Nm:$80.;
&amp;nbsp; datalines;
Steve's Plumbing
;
run;

proc sql;
create table want as
 select * from Industry,Company_Name
&amp;nbsp; where Company_Nm contains strip(Industry_Nm);
&amp;nbsp; quit;
 

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 13:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-array-lookups/m-p/189111#M47787</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-06-09T13:26:52Z</dc:date>
    </item>
  </channel>
</rss>

