<?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: Proc Import Reference multiple Spreadsheets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334691#M272269</link>
    <description>&lt;P&gt;I'm not familiar with the concept of arrays in excel. Do you mean named ranges?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I, for one, would need a better description of what your workbooks look like in order to provide any suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attaching one of them would really help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Tue, 21 Feb 2017 15:59:45 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-02-21T15:59:45Z</dc:date>
    <item>
      <title>Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334656#M272263</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the code shown below I want to reference multiple sheets and create only one table&lt;/P&gt;&lt;P&gt;my excel file has multiple spreadsheets..&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;M00_ACCT_BAL_AM&amp;nbsp;to&amp;nbsp;&lt;SPAN&gt;M24_ACCT_BAL_AM (25 spreadsheets)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;M00_ACCT_CR_AM to &amp;nbsp;M24_ACCT_CR_AM&amp;nbsp;(25 spreadsheets)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How Can I reference them on my macro?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks and regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_loop;
%let outobs=max;
%do i1=0  %to 24;
%let i = %sysfunc( putn(&amp;amp;i1,z2.));
%let sheet="M&amp;amp;i._ACCT_BAL_AM"; /* Not Working */
%let sheet="M&amp;amp;i_ACCT_CR_AM"; /* Not Working */
proc import 			out  		= testv1_&amp;amp;i (rename =('Current %'n=Current_per 'Previous %'n=Previous_per '% Change'n=Change_per)) 
    				datafile 	= '/test/DVR_V1_PROD_01182017.xls'
    				dbms 		= xls replace ;
    				sheet		= "&amp;amp;sheet"; /*I want to reference both Arrays */&lt;BR /&gt;                                 /*sheet = "M&amp;amp;i._ACCT_BAL_AMT"; this worked but I need to reference 2 different arrays*/ 
    				getnames 	= yes;

						
run;

data testv1_&amp;amp;i (drop='Run Date:'n I) ;
set testv1_&amp;amp;i ;
run;

data allMyData (keep=SheetObject Range_Start Range_End Current_Count 
Previous_Count Current_per	 Previous_per	Change_per);
length SheetObject $32;
set testv1_: 
indsname=name ; 
Rename 
'Range Start'n=Range_Start	
'Range End'n =Range_End	
'Current Count'n=Current_Count
'Previous Count'n=Previous_Count
;
SheetObject = cats("M", scan(name, 3, "._") , "_ACCT_BAL_AM"); 
run;

%end;
%mend import_loop;&lt;/CODE&gt;&lt;/PRE&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>Tue, 21 Feb 2017 14:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334656#M272263</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-21T14:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334659#M272264</link>
      <description>&lt;P&gt;Do you have SAS 9.4 and are the files actual .XLSX files? &amp;nbsp;If so then save yourself some time and use libname excel:&lt;/P&gt;
&lt;PRE&gt;libname f1 excel "&amp;lt;pathtofile&amp;gt;\M00_ACCT_BAL_AM to M24_ACCT_BAL_AM.xlsx";
&lt;/PRE&gt;
&lt;P&gt;Then you can do most things with each tab as:&lt;/P&gt;
&lt;PRE&gt;data want;
  set f1.Sheet1;
run;&lt;/PRE&gt;
&lt;P&gt;And if you want to know what sheets are in the file:&lt;/P&gt;
&lt;PRE&gt;data want;
  set sashelp.vtable (where=(libname="F1"));
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2017 14:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334659#M272264</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-21T14:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334663#M272265</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have my excel file in "xls" format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way that I can reference them like &amp;nbsp;**Keyword parameters** &amp;nbsp;??&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_loop (sheet=,);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2017 14:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334663#M272265</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-21T14:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334666#M272266</link>
      <description>&lt;P&gt;Well, you need to tell the program what the sheet names are somehow. &amp;nbsp;If the sheet names remain constant then you can do:&lt;/P&gt;
&lt;PRE&gt;%macro import_sheet (sheet=);
  proc import...;
    sheet="&amp;amp;sheet.";
  run;
%mend import_sheet;

data _null_;
  length sheet $200;
  input sheet $;
  call execute(cats('%import_sheet (sheet=',sheet,');'));
datalines;
Sheet1
Sheet_abc
...
;
run;&lt;/PRE&gt;
&lt;P&gt;What would be better however is to drop the XLS format which is ancient history in terms of file formats, or alternatively drop Excel altogether. &amp;nbsp;Have a small VBA script dump the contents of the XLS out to separate CSV files, then have a datastep read each one in using a fixed import program. &amp;nbsp;Excel is a really bad data medium, and then you confound this by using a guessing procedure (proc import) to get data from there.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 14:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334666#M272266</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-21T14:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334672#M272267</link>
      <description>&lt;P&gt;Before wrapping the code in a macro, I strongly suggest getting the code down to run one import successfully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You won't know what names will be assigned when non-conforming SAS names are found UNTIL you run such code. Some versions of proc import delete the first character of a variable name in such cases, while others replace them with an underscore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following worked on my system:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc import         out  		= testb1_01 (rename =(Current__=Current_per Previous__=Previous_per __Change=Change_per))
    				datafile 	= '/test/DVR_V1_PROD_01182017.xls'
    				dbms 		= xls replace ;
    				sheet		= "M00_ACCT_BAL_AM"; /*I want to reference both Arrays */                                 /*sheet = "M&amp;amp;i._ACCT_BAL_AMT"; this worked but I need to reference 2 different arrays*/ 
    				getnames 	= yes;
run;
&lt;/PRE&gt;
&lt;P&gt;If that works for you, then you can accomodate the two sets of sheets with something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let bsheet="M&amp;amp;i._ACCT_BAL_AM"; /* Not Working */
%let csheet="M&amp;amp;i_ACCT_CR_AM"; /* Not Working */
proc import 		out  		= testb1_&amp;amp;i. (rename =(Current__=Current_per Previous__=Previous_per __Change=Change_per)) 
    				datafile 	= '/test/DVR_V1_PROD_01182017.xls'
    				dbms 		= xls replace ;
    				sheet		= "&amp;amp;bsheet."; /*I want to reference both Arrays */                                 /*sheet = "M&amp;amp;i._ACCT_BAL_AMT"; this worked but I need to reference 2 different arrays*/ 
    				getnames 	= yes;

						
run;

proc import 		out  		= testc1_&amp;amp;i. (rename =(Current__=Current_per Previous__=Previous_per __Change=Change_per)) 
    				datafile 	= '/test/DVR_V1_PROD_01182017.xls'
    				dbms 		= xls replace ;
    				sheet		= "&amp;amp;csheet."; /*I want to reference both Arrays */                                 /*sheet = "M&amp;amp;i._ACCT_BAL_AMT"; this worked but I need to reference 2 different arrays*/ 
    				getnames 	= yes;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 15:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334672#M272267</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-21T15:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334686#M272268</link>
      <description>&lt;P&gt;I was planning to do different with **proc import**, Actually I have 6 arrays on my excel file.&lt;/P&gt;&lt;P&gt;So my assumption was weather I can do the **proc import** with 2 arrays in only one import I would be able to do it for 6 arrays&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought this part could be referenced in only one macro variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let bsheet="M&amp;amp;i._ACCT_BAL_AM"; /* Not Working */
%let csheet="M&amp;amp;i_ACCT_CR_AM"; /* Not Working */&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems like it will be very tough make it in only **one import**, so the best solution should be generate 6 macro variables with each array??&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 15:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334686#M272268</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-21T15:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334691#M272269</link>
      <description>&lt;P&gt;I'm not familiar with the concept of arrays in excel. Do you mean named ranges?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I, for one, would need a better description of what your workbooks look like in order to provide any suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attaching one of them would really help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 15:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334691#M272269</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-21T15:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334696#M272270</link>
      <description>&lt;P&gt;Yes, I mean basically about **Ranges**&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to import 150 spreadsheet from one excel file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an example of the names of the &amp;nbsp;excel sheets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;M00_ACCT_BAL_AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;to&amp;nbsp;&lt;SPAN&gt;M24_ACCT_BAL_AM ( 25 workbooks)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;M00_ACCT_CRED_LIM_AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; to&amp;nbsp;M24_ACCT_CRED_LIM_AM&amp;nbsp;( 25 workbooks)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.. so on ...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and total number is 150&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 16:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334696#M272270</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-21T16:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334767#M272271</link>
      <description>With a libname statement using the excel engine,  each of the range names (subject to the validvarname=v7 rules) can be used as table names.&lt;BR /&gt;It is as if, under the hood, an import is performed for each range. However, your datastep SET statement only lists the multiple libref.range_name.&lt;BR /&gt;One convenience  I have used before:&lt;BR /&gt;PROC SQL nolist ;&lt;BR /&gt;select catx('.', libname, memname) &lt;BR /&gt;  into :ranges separated by ' '&lt;BR /&gt;  from dictionary.members&lt;BR /&gt; where libname = 'LIBREF'&lt;BR /&gt;   and memname not contain '$' &lt;BR /&gt;      ;&lt;BR /&gt;Quit ;&lt;BR /&gt;* replace LIBREF with your exvel libname statement libref.;&lt;BR /&gt;data work.all_ranges ;&lt;BR /&gt; Set.&amp;amp;ranges ;&lt;BR /&gt;run ;&lt;BR /&gt;&lt;BR /&gt;Further conditions in the WHERE clause could restrict the range names if needed.&lt;BR /&gt;If you have and need to use, range names which do not comply with the V7 rules, try the NLITERAL() function on the memname value.&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Feb 2017 20:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334767#M272271</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-02-21T20:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import Reference multiple Spreadsheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334858#M272272</link>
      <description>&lt;P&gt;Yes, you can use libname as I mention above. &amp;nbsp;However it sounds like - and this is quite common, you have a real mess of Excel. &amp;nbsp;This is typical with an unstructured free for all that is Excel. &amp;nbsp;In most cases when I get something like this (well after going mad at whoever provided such a thing) is to process it using VBA which is embedded in Excel. &amp;nbsp;Its a very simple language. &amp;nbsp;Basically loop over your ranges and dump the data to a csv, literally a couple of lines of code:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/27234134/loop-through-all-named-ranges-in-a-excel-sheet" target="_blank"&gt;http://stackoverflow.com/questions/27234134/loop-through-all-named-ranges-in-a-excel-sheet&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Add a SaveAS to the above's solution and voila. &amp;nbsp;I would dump all the data out to one CSV putting the name of the range as variable 1 - assuming the data is all the same? - if its not, then how are you going to use the data further? &amp;nbsp;If it is the same then one datastep to import that one CSV file, then you have one dataset with all the data and a variable which identifies which named range it came from.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 09:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-Reference-multiple-Spreadsheets/m-p/334858#M272272</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-22T09:17:35Z</dc:date>
    </item>
  </channel>
</rss>

