<?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: XLSX libname PROC COPY specify a range to apply to all sheets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/XLSX-libname-PROC-COPY-specify-a-range-to-apply-to-all-sheets/m-p/678663#M204857</link>
    <description>&lt;P&gt;John,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you try firstobs option ?&lt;/P&gt;
&lt;PRE&gt;options firstobs=2;
libname x v9 'c:\temp\';
proc copy in=work out=x;
select have;
run;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Aug 2020 12:19:08 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-08-22T12:19:08Z</dc:date>
    <item>
      <title>XLSX libname PROC COPY specify a range to apply to all sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XLSX-libname-PROC-COPY-specify-a-range-to-apply-to-all-sheets/m-p/678551#M204812</link>
      <description>&lt;P&gt;My variable names are on row 2.&amp;nbsp; I would like to PROC COPY all sheets with range $A2:0 but I don't know if it is possible or if I just can't figure the syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;30         libname xl xlsx './zzzzzzzzzzz.xlsx' access=read;
NOTE: Libref XL was successfully assigned as follows: 
      Engine:        XLSX 
      Physical Name: (system-specific file/path name)
31         
32         data test;
33            set xl.'ADJAE007$A2:0'n;
34            run;

NOTE: The import data set has 122 observations and 13 variables.
NOTE: The data set WORK.TEST has 122 observations and 13 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.02 seconds
37         
38         proc copy in=xl out=work;
39            select 'ADJAE007$A2:0'n;
40            run;

ERROR: The file XL.ADJAE007$A2:0 (memtype=ALL) was not found, but appears on a SELECT statement.
NOTE: Statements not processed because of errors noted above.&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Aug 2020 18:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XLSX-libname-PROC-COPY-specify-a-range-to-apply-to-all-sheets/m-p/678551#M204812</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2020-08-21T18:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: XLSX libname PROC COPY specify a range to apply to all sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XLSX-libname-PROC-COPY-specify-a-range-to-apply-to-all-sheets/m-p/678663#M204857</link>
      <description>&lt;P&gt;John,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you try firstobs option ?&lt;/P&gt;
&lt;PRE&gt;options firstobs=2;
libname x v9 'c:\temp\';
proc copy in=work out=x;
select have;
run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Aug 2020 12:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XLSX-libname-PROC-COPY-specify-a-range-to-apply-to-all-sheets/m-p/678663#M204857</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-08-22T12:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: XLSX libname PROC COPY specify a range to apply to all sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/XLSX-libname-PROC-COPY-specify-a-range-to-apply-to-all-sheets/m-p/678721#M204898</link>
      <description>&lt;P&gt;The XLSX libname requires that the sheets be constructed like a dataset.&amp;nbsp; But you can use it to help you get the list of sheet names to use in generating code to read starting from the second row.&lt;/P&gt;
&lt;P&gt;So make a libname pointing to the XLSX file and get the list of members, for example by using PROC CONTENTS.&amp;nbsp; Then use that list of members to generate PROC IMPORT code as below or the data step code in your example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While you are at it you could add some logic to deal with sheet names that are not valid dataset names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=C:\downloads\;
%let fname=Myfile.xlsx;
libname OUT "&amp;amp;path.sas";
libname IN xlsx "&amp;amp;path.&amp;amp;fname";

* Set VALIDMEMNAME option to EXTEND to handle sheetnames with spaces ;
* Set VALIDVARNAME option to V7 ;
options validmemname=extend validvarname=v7;

* Get contents information from source workbook ;
proc contents data=IN._all_ noprint out=sheets(keep=memname);
run;
libname IN clear;
* Reset VALIDMEMNAME option to COMPAT ;
options validmemname=compat;

* Keep one observations per sheet ;
* Generate RANGE from sheet name;
* Generate valid MEMNAME from the SHEET names ;
* Generate PROC IMPORT code to read from second row and write to OUT library ;
data sheets;
  set sheets ;
  if memname ne lag(memname);
  length range $50 ;
  range=quote(cats(memname,'$A2:'));
  memname=translate(trim(prxchange('s/([^a-zA-Z0-9]+)/ /',-1,memname)),' _','_ ');
  memname=prxchange('s/(^[0-9])/_$1/',1,memname);
  call execute(catx(' ','proc import dbms=xlsx datafile="&amp;amp;path\&amp;amp;fname" replace'
                       ,cats('out=out.',memname),';','range=',range,';run;'));
run;

proc print data=sheets;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 14:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/XLSX-libname-PROC-COPY-specify-a-range-to-apply-to-all-sheets/m-p/678721#M204898</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-23T14:24:16Z</dc:date>
    </item>
  </channel>
</rss>

