<?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 Excel libname firstobs option in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Excel-libname-firstobs-option/m-p/713925#M220324</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have copied multiple years of data tables into an Excel xlsx file with sheets named for each year (ex. 2005, 2006, ... 2018).&amp;nbsp; I used a libname statement specifying the xlsx engine to create a SAS library that accesses the sheets from the Excel workbook.&amp;nbsp; I have run into two problems with this.&amp;nbsp; First, although I am using the firstobs= and obs= options to specify rows for data input, the data step is importing data from one row below each specified value.&amp;nbsp; For example, I wrote the program below to import rows 3-54 from the Excel sheet.&amp;nbsp; However, it brought in rows 4-55.&amp;nbsp;&amp;nbsp;Does anyone know why this is happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My second question involves naming variables.&amp;nbsp; I tried using an input statement, as I typically use when importing raw data within data steps, but I received an error message "No datalines or infile statement".&amp;nbsp; Could anyone tell me how to specify variable names and informats when using an Excel file as a library?&amp;nbsp; I could not find an example in SAS documentation where they specified variable names.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname SHEETS xlsx "S:\Data Files\OPA FPAR\States.xlsx";
data fpar_2005;
	set SHEETS.'2005'n(firstobs = 3 obs = 54);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Also, I do not see in SAS documentation how to use the equivalent of an input state&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ted&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jan 2021 15:24:06 GMT</pubDate>
    <dc:creator>LEINAARE</dc:creator>
    <dc:date>2021-01-25T15:24:06Z</dc:date>
    <item>
      <title>Excel libname firstobs option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-libname-firstobs-option/m-p/713925#M220324</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have copied multiple years of data tables into an Excel xlsx file with sheets named for each year (ex. 2005, 2006, ... 2018).&amp;nbsp; I used a libname statement specifying the xlsx engine to create a SAS library that accesses the sheets from the Excel workbook.&amp;nbsp; I have run into two problems with this.&amp;nbsp; First, although I am using the firstobs= and obs= options to specify rows for data input, the data step is importing data from one row below each specified value.&amp;nbsp; For example, I wrote the program below to import rows 3-54 from the Excel sheet.&amp;nbsp; However, it brought in rows 4-55.&amp;nbsp;&amp;nbsp;Does anyone know why this is happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My second question involves naming variables.&amp;nbsp; I tried using an input statement, as I typically use when importing raw data within data steps, but I received an error message "No datalines or infile statement".&amp;nbsp; Could anyone tell me how to specify variable names and informats when using an Excel file as a library?&amp;nbsp; I could not find an example in SAS documentation where they specified variable names.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname SHEETS xlsx "S:\Data Files\OPA FPAR\States.xlsx";
data fpar_2005;
	set SHEETS.'2005'n(firstobs = 3 obs = 54);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Also, I do not see in SAS documentation how to use the equivalent of an input state&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ted&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 15:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-libname-firstobs-option/m-p/713925#M220324</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2021-01-25T15:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Excel libname firstobs option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-libname-firstobs-option/m-p/713950#M220328</link>
      <description>&lt;P&gt;SAS is probably cinsidering row 1 in Excel as header (variable) information, wheras the firstobs= optins refeers to datalines processed by the data step. Set firstobs=2 if you want to ommit the header row and an additionl row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you own the Excel spreadhsheet the simplest is to use headers that comply with SAS variable naming rules.&lt;/P&gt;
&lt;P&gt;You can't/shouldn't use input with the Excel libname engine - the engine itself defines/decides table and column/variable names.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 15:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-libname-firstobs-option/m-p/713950#M220328</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2021-01-25T15:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Excel libname firstobs option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-libname-firstobs-option/m-p/713951#M220329</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;. I think I will just rename the variable names SAS assigns.</description>
      <pubDate>Mon, 25 Jan 2021 16:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-libname-firstobs-option/m-p/713951#M220329</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2021-01-25T16:02:06Z</dc:date>
    </item>
  </channel>
</rss>

