<?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: extract libnames from excel and create macro variable to call libnames in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855074#M337976</link>
    <description>&lt;P&gt;It looks like your dataset imported from Excel contains logical names and physical path names, to be used in LIBNAME statements.&lt;/P&gt;
&lt;P&gt;To execute a series of LIBNAME statements, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set have; /* or whatever your datase is named */
call execute('libname ` !! href !! ' "' !! strip(path) !!'";');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming the second variable in your dataset is named PATH.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jan 2023 12:44:13 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-01-23T12:44:13Z</dc:date>
    <item>
      <title>extract libnames from excel and create macro variable to call libnames</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855059#M337964</link>
      <description>&lt;P&gt;I have an excel file which contains libnames&amp;nbsp; and i need to&amp;nbsp;extract libnames from excel and create macro variable to call libnames.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use proc import to import the libnames and then use the below code but since my libname has ":" it gives error&lt;/P&gt;
&lt;P&gt;! C:\Programming\check&lt;/P&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, &lt;BR /&gt;KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Concatenate the list of LIBNAMEs into a single macro variable */
data _null_;
    set libname_list;
    if _n_ = 1 then call symputx('libnames', Href);
    else call symputx('libnames', symget('libnames') || ' ' || Href);
run;
/* Create a macro variable to call the assigned LIBNAMEs */&lt;BR /&gt;
%let libnames_list = &amp;amp;libnames;

/* Perform some action on the assigned LIBNAMEs */
data _null_;
    set &amp;amp;libnames_list;
  
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Can anyone help on how to create macro which can be called on each program to get libnames&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 11:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855059#M337964</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2023-01-23T11:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: extract libnames from excel and create macro variable to call libnames</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855060#M337965</link>
      <description>&lt;P&gt;Please post the complete log using "insert code" and show the contents of "libname_list", usable form preferred.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 11:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855060#M337965</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-01-23T11:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: extract libnames from excel and create macro variable to call libnames</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855063#M337968</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Excel with libname looks like this&lt;BR /&gt;          Href&lt;BR /&gt;_01 "C:\Programming\check1"
_02  "C:\Programming\check2"
_03 "C:\Programming\check3"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then after proc import i use the below code to create macro variable so that i can call it in each individual program&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Concatenate the list of LIBNAMEs into a single macro variable */
data _null_;
    set libname_list;
    if _n_ = 1 then call symputx('libnames', Href);
    else call symputx('libnames', symget('libnames') || ' ' || Href);
run;

/* Create a macro variable to call the assigned LIBNAMEs */
%let libnames_list = &amp;amp;libnames;

/* Perform some action on the assigned LIBNAMEs */
data _null_;
    set &amp;amp;libnames_list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get the below error in log&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;      data _null_;
48             set &amp;amp;libnames_list;
ERROR: File WORK._01.DATA does not exist.
ERROR: File C:\Programming\check1 does not exist.
ERROR: File WORK._02.DATA does not exist.
ERROR: File C:\Programming\check2 does not exist.
ERROR: File WORK._03.DATA does not exist.
ERROR: File C:\Programming\check3 does not exist.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jan 2023 11:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855063#M337968</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2023-01-23T11:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: extract libnames from excel and create macro variable to call libnames</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855065#M337969</link>
      <description>&lt;P&gt;Please attach a sample Excel that is fully representative of your actual data (just a few lines) - even the ones not downloading Excels can preview the content to understand what you're really dealing with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To use a SAS table in a data step it must either be accessed via &amp;lt;libref&amp;gt;.&amp;lt;table name&amp;gt; or then fully qualified as &amp;lt;path&amp;gt;/&amp;lt;file name&amp;gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming check2 is a SAS table for your data _null_ step generated syntax would need to look either...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname aa 'c:\Programming';
data _null_;
   set aa.check2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...or...&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set 'c:\Programming\check2.sas7bdat' ;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And last but not least: Your data step for creating the macro variable with concatenated values works but usually that's done using code as follows:&lt;/P&gt;
&lt;PRE&gt;%let libnames=;
proc sql noprint;
  select href into :libnames separated by ' '
  from libname_list
  ;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 12:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855065#M337969</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-23T12:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: extract libnames from excel and create macro variable to call libnames</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855068#M337971</link>
      <description>&lt;P&gt;Please look at the SAS data set named&amp;nbsp;libname_list and determine if it has been created correctly from the Excel file. Please show us (a portion of) the SAS data set named&amp;nbsp;libname_list (NOT the Excel file) as working data step code, which you can type yourself or follow &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 12:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855068#M337971</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-23T12:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: extract libnames from excel and create macro variable to call libnames</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855074#M337976</link>
      <description>&lt;P&gt;It looks like your dataset imported from Excel contains logical names and physical path names, to be used in LIBNAME statements.&lt;/P&gt;
&lt;P&gt;To execute a series of LIBNAME statements, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set have; /* or whatever your datase is named */
call execute('libname ` !! href !! ' "' !! strip(path) !!'";');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming the second variable in your dataset is named PATH.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 12:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855074#M337976</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-23T12:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: extract libnames from excel and create macro variable to call libnames</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855079#M337978</link>
      <description>&lt;P&gt;Thanks Kurt, It works. I have one more question. How do i make it as a macro so that i can use on seperate programs?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 13:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855079#M337978</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2023-01-23T13:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: extract libnames from excel and create macro variable to call libnames</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855102#M337988</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/62004"&gt;@vraj1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Kurt, It works. I have one more question. How do i make it as a macro so that i can use on seperate programs?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do mean different SAS sessions?&lt;/P&gt;
&lt;P&gt;Once a libname is defined in a SAS session it persists unless you explicitly clear it. So run this bit once and all your other programs have the libraries available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if other users, which would mean different sessions, you could use %include to point to a common location source code and have them execute as needed but that would assume that all the files/ paths are the same.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 15:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-libnames-from-excel-and-create-macro-variable-to-call/m-p/855102#M337988</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-23T15:37:44Z</dc:date>
    </item>
  </channel>
</rss>

