<?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 XLSX with Libname Instead of Full Filename in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886869#M350428</link>
    <description>&lt;P&gt;Macro variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file_path = C:\Users\Example1\Example2;

Proc import out= want
datafile="&amp;amp;file_path.\Main.want.xlsx"
dbms=xlsx replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446308"&gt;@bttomblin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As a newer SAS user, I have learned the "proc import" method of importing .xlsx files using the full filename. Now that I am working with more files, I wanted to see if it was possible to use a defined libname or path when importing instead of the full filename. That way, if I have to move files to a new folder, I only have to change the path in one location instead of many.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I currently use this:&lt;BR /&gt;Proc import out= want&lt;BR /&gt;datafile="C:\Users\Example1\Example2\want.xlsx"&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I want to know if there's any way to do something like:&lt;/P&gt;
&lt;P&gt;libname Main "C:\Users\Example1\Example2";&lt;/P&gt;
&lt;P&gt;Proc import out= want&lt;BR /&gt;datafile=Main.want.xlsx&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my first post on these forums, so let me know if I need more information. Thank you for any help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2023 17:37:41 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-07-28T17:37:41Z</dc:date>
    <item>
      <title>Proc Import XLSX with Libname Instead of Full Filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886837#M350413</link>
      <description>&lt;P&gt;As a newer SAS user, I have learned the "proc import" method of importing .xlsx files using the full filename. Now that I am working with more files, I wanted to see if it was possible to use a defined libname or path when importing instead of the full filename. That way, if I have to move files to a new folder, I only have to change the path in one location instead of many.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I currently use this:&lt;BR /&gt;Proc import out= want&lt;BR /&gt;datafile="C:\Users\Example1\Example2\want.xlsx"&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I want to know if there's any way to do something like:&lt;/P&gt;&lt;P&gt;libname Main "C:\Users\Example1\Example2";&lt;/P&gt;&lt;P&gt;Proc import out= want&lt;BR /&gt;datafile=Main.want.xlsx&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my first post on these forums, so let me know if I need more information. Thank you for any help!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 16:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886837#M350413</guid>
      <dc:creator>bttomblin</dc:creator>
      <dc:date>2023-07-28T16:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import XLSX with Libname Instead of Full Filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886853#M350421</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446308"&gt;@bttomblin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc import and XLSX libname are two different things.&amp;nbsp;With Proc Import, you specify the XLSX file and (optional) the sheet to import, if there are more than one.&lt;/P&gt;
&lt;P&gt;With&amp;nbsp;XLSX libname, you assign the XLSX file (not the folder) as a libname, and the sheets are seen as members in the libname. The correct syntax is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname main XLSX "C:\Users\Example1\Example2\want.xlsx";

* Copy all sheets to work; 
proc copy inlib=main outlib=work;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jul 2023 17:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886853#M350421</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-07-28T17:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import XLSX with Libname Instead of Full Filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886869#M350428</link>
      <description>&lt;P&gt;Macro variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file_path = C:\Users\Example1\Example2;

Proc import out= want
datafile="&amp;amp;file_path.\Main.want.xlsx"
dbms=xlsx replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446308"&gt;@bttomblin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As a newer SAS user, I have learned the "proc import" method of importing .xlsx files using the full filename. Now that I am working with more files, I wanted to see if it was possible to use a defined libname or path when importing instead of the full filename. That way, if I have to move files to a new folder, I only have to change the path in one location instead of many.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I currently use this:&lt;BR /&gt;Proc import out= want&lt;BR /&gt;datafile="C:\Users\Example1\Example2\want.xlsx"&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I want to know if there's any way to do something like:&lt;/P&gt;
&lt;P&gt;libname Main "C:\Users\Example1\Example2";&lt;/P&gt;
&lt;P&gt;Proc import out= want&lt;BR /&gt;datafile=Main.want.xlsx&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my first post on these forums, so let me know if I need more information. Thank you for any help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 17:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886869#M350428</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-28T17:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import XLSX with Libname Instead of Full Filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886873#M350431</link>
      <description>&lt;P&gt;I did see this as an option, but I think it would have the same issue of needing to update every xlsx library if files moved. Thank you for the response, though.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 18:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886873#M350431</guid>
      <dc:creator>bttomblin</dc:creator>
      <dc:date>2023-07-28T18:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import XLSX with Libname Instead of Full Filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886874#M350432</link>
      <description>&lt;P&gt;Macros were going to be my fallback if what I proposed didn't exist. I agree with you that I think that is the closest to a one-place-change variable to edit should my file paths change. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 18:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886874#M350432</guid>
      <dc:creator>bttomblin</dc:creator>
      <dc:date>2023-07-28T18:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import XLSX with Libname Instead of Full Filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886881#M350435</link>
      <description>&lt;P&gt;You could get the path from the libref (or fileref) instead of using a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import file="%sysfunc(pathname(MYLIB))/myfile.xlsx" ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 18:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886881#M350435</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-28T18:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Import XLSX with Libname Instead of Full Filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886900#M350440</link>
      <description>&lt;P&gt;Just for consideration have you compared the results of importing two or more XLSX files that are supposed to contain similar data? Compare meaning look at&lt;/P&gt;
&lt;P&gt;1) variable names&lt;/P&gt;
&lt;P&gt;2) variable types&lt;/P&gt;
&lt;P&gt;3) length of variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Import makes guesses for each file. You will find literally dozens if not hundreds of topics on this forum related to importing multiple similar XLSX files and getting results where data gets truncated when combining sets because of defined lengths or cannot combine files at all because the type for the same named variables are different.&lt;/P&gt;
&lt;P&gt;Or can't use with other external programs as needed because account numbers and such have had leading 0, zero, removed when a value is treated as numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two different installs running Proc Import may even get different results based on custom settings.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 20:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Import-XLSX-with-Libname-Instead-of-Full-Filename/m-p/886900#M350440</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-28T20:06:03Z</dc:date>
    </item>
  </channel>
</rss>

