<?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: Look Up Table from Excel File in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665048#M198777</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME exfiles XLSX '[drive:]\test_xlsx_lkup.xlsx';
options validvarname='any';

proc contents data=exfiles._all_; run;
proc sql;
	select term
		,'43986'n
	from exfiles.sheet1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Additional examples can be found here&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/05/20/using-libname-xlsx-to-read-and-write-excel-files/" target="_blank" rel="noopener"&gt;Using LIBNAME XLSX to read and write Excel files&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2020/03/10/accessing-excel-files-using-libname-xlsx/" target="_blank" rel="noopener"&gt;Accessing Excel files using LIBNAME XLSX&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jun 2020 15:47:46 GMT</pubDate>
    <dc:creator>AhmedAl_Attar</dc:creator>
    <dc:date>2020-06-25T15:47:46Z</dc:date>
    <item>
      <title>Look Up Table from Excel File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665040#M198774</link>
      <description>&lt;P&gt;I need some help using a lookup table in SAS that looks like the following. The table comes from an Excel file that produced by someone else and I have no way to change the&amp;nbsp;structure of the table. I would like to be able use the table to join where the Term and Date in the first row match another table. Any way to accomplish this in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Term&lt;/TD&gt;&lt;TD&gt;6/1/2020&lt;/TD&gt;&lt;TD&gt;6/2/2020&lt;/TD&gt;&lt;TD&gt;6/3/2020&lt;/TD&gt;&lt;TD&gt;6/4/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 15:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665040#M198774</guid>
      <dc:creator>LB3</dc:creator>
      <dc:date>2020-06-25T15:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Look Up Table from Excel File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665048#M198777</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME exfiles XLSX '[drive:]\test_xlsx_lkup.xlsx';
options validvarname='any';

proc contents data=exfiles._all_; run;
proc sql;
	select term
		,'43986'n
	from exfiles.sheet1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Additional examples can be found here&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/05/20/using-libname-xlsx-to-read-and-write-excel-files/" target="_blank" rel="noopener"&gt;Using LIBNAME XLSX to read and write Excel files&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2020/03/10/accessing-excel-files-using-libname-xlsx/" target="_blank" rel="noopener"&gt;Accessing Excel files using LIBNAME XLSX&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 15:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665048#M198777</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2020-06-25T15:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Look Up Table from Excel File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665055#M198780</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/244972"&gt;@LB3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The table comes from an Excel file that produced by someone else and I have no way to change the&amp;nbsp;structure of the table.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why do you have no way to change the structure? Import the data from Excel and then use PROC TRANSPOSE and a standard merge after that. Assuming your date variables are named something like _date1 _date2 this may work. There are ways to easily list all your other variables if you don't have a naming convention.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=dates out=long_dates;
by term;
var _: ; *you need to put the list of variable names here;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Here is a reference that illustrates how to refer to variables and datasets in a short cut list:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 16:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665055#M198780</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-25T16:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Look Up Table from Excel File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665225#M198866</link>
      <description>&lt;P&gt;How are you reading the Excel table ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you Proc IMPORT the&amp;nbsp; Excel file the date valued columns in SAS will be&amp;nbsp;named _&amp;lt;excel-date-number&amp;gt;.&lt;/P&gt;
&lt;P&gt;Perform a transpose BY TERM and compute the SAS date value from the _NAME_ value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example (untested)&lt;/P&gt;
&lt;PRE&gt;Proc IMPORT datafile='SomeoneElse.xlsx' dbms=xlsx replace out=lookup_raw;
Proc TRANSPOSE data=lookup_raw out=lookup_base;&lt;BR /&gt;  by TERM;&lt;BR /&gt;  var _:;&lt;BR /&gt;run;&lt;BR /&gt;data lookup;&lt;BR /&gt;  set lookup_base;&lt;BR /&gt;  xl_date = input (substr(_name_,2),8.);&lt;BR /&gt;  date = xl_date &lt;CODE&gt;+ '31dec1899'd;&lt;BR /&gt;  format date date9.;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can join&lt;/P&gt;
&lt;PRE&gt;select
   ...
   , COL1 as LookupValue
from 
  other_table as A
join 
  lookup as LU
on 
  A.date = LU.date and A.TERM=LU.TERM&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jun 2020 03:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-Up-Table-from-Excel-File/m-p/665225#M198866</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-06-26T03:22:25Z</dc:date>
    </item>
  </channel>
</rss>

