<?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: Creating a concatenated Libname using a macro (%let) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566362#M159158</link>
    <description>Actually, on my version of SAS it generates a warning but not an&lt;BR /&gt;error, and writes to the first sub-directory that is valid.&lt;BR /&gt;&lt;BR /&gt;810 libname test ('d:\data\Recap III' 'd:\data\recap');&lt;BR /&gt;WARNING: One or more libraries specified in the concatenated library&lt;BR /&gt;TEST do not exist. These libraries were removed from the concatenation.&lt;BR /&gt;NOTE: Libref TEST was successfully assigned as follows:&lt;BR /&gt;Levels: 1&lt;BR /&gt;Engine(1): V9&lt;BR /&gt;Physical Name(1): d:\data\recap&lt;BR /&gt;811 data test.temp;x=1;run;&lt;BR /&gt;&lt;BR /&gt;NOTE: The data set TEST.TEMP has 1 observations and 1 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;812 proc contents data=test.temp;run;&lt;BR /&gt;&lt;BR /&gt;NOTE: PROCEDURE CONTENTS used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sat, 15 Jun 2019 13:34:17 GMT</pubDate>
    <dc:creator>Bahr</dc:creator>
    <dc:date>2019-06-15T13:34:17Z</dc:date>
    <item>
      <title>Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565667#M158847</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I sometimes work on my desktop and sometimes on my laptop.&amp;nbsp; When I work on my laptop, I access files on the desk via the network, both the data and the jobs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So when I am on the desktop I have this, accessing the data which is on desktop:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname data1 "d:\data1";&lt;/P&gt;&lt;P&gt;libname data2 "d:\data2";&lt;/P&gt;&lt;P&gt;libname data3 "d:\data3";&lt;/P&gt;&lt;P&gt;libname data4 "d:\data4";&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I am on the laptop, I access the data on the desktop using the name for the desktop on the network:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname data1 "\\SmithDT\data1";&lt;/P&gt;&lt;P&gt;libname data2 "\\SmithDT\data2";&lt;/P&gt;&lt;P&gt;libname data3 "\\SmithDT\data3";&lt;/P&gt;&lt;P&gt;libname data4 "\\SmithDT\data4";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What that means is every time I switch back and forth between the desktop and the laptop, I have to change or comment out the libname that is not correct.&amp;nbsp; I would like be able to set it up where I only make one change, the drive name (depending on whether I am on the desktop or laptop), and have it concatenate with the subdirectory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using %Let Drive="d:\" or %Let Drive="\\SmithDT" , and %Let SubDir="data", but then it does not seem possible to concatenate &amp;amp;Drive and &amp;amp;Subdir, because the ' becomes part of the value of the macro variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any ideas, I'm using SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 20:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565667#M158847</guid>
      <dc:creator>Bahr</dc:creator>
      <dc:date>2019-06-12T20:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565674#M158850</link>
      <description>&lt;P&gt;Don't put quotes around the macro variable and that's all. You can also just add some conditional logic for the program to detect where you're running from and then conditionally run one set of the code. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let drive =D:\;

libname data1 = "&amp;amp;drive.\data1";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;You can also use the LIBNAME function in a data step which allows you to dynamically build your string. &lt;BR /&gt;&lt;BR /&gt;In general, a lot of options to solve this issue.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 20:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565674#M158850</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-12T20:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565676#M158851</link>
      <description>&lt;P&gt;Using a UNC path should work on both computers -&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;libname data1 "\\SmithDT\data1"; -&amp;nbsp; then you wouldn't need to change any code.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 20:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565676#M158851</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-06-12T20:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565678#M158852</link>
      <description>&lt;P&gt;In macro code quotes are just like any other character (although strings inside of single quotes are not processed by the macro processor).&amp;nbsp; So you should NOT include the quotes in the value of your macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let top=D:;
libname data1 "&amp;amp;top\data1";
libname data2 "&amp;amp;top\data2";
libname data3 "&amp;amp;top\data3";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In regular SAS code you need quotes around strings so that the compiler knows you mean a sting literal and not a name or keyword. But&amp;nbsp; the macro processor just looks for &amp;amp; and % triggers to know when it needs to take action so there is no need to add the quotes.&amp;nbsp; Just add quotes into the code that you are using the macro variables (or macro code) to generate where SAS itself needs the quotes. Like the quotes around the path in the LIBNAME statement above.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 20:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565678#M158852</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-12T20:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565742#M158886</link>
      <description>&lt;P&gt;You've had replies about how macro variables are just literal text that get resolved during program compilation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've also had the suggestion to use the UNC path for both scenarios.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that doesn't work for some reason, you can try this approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro allocate_libraries;
   %let computername=%sysget(COMPUTERNAME);
   %if (&amp;amp;computername eq FOO) %then %do;
      libname data1 "d:\data1";
      libname data2 "d:\data2";
      libname data3 "d:\data3";
      libname data4 "d:\data4";
   %end;
   %else
   %if (&amp;amp;computername eq BAR) %then %do;
      libname data1 "\\SmithDT\data1";
      libname data2 "\\SmithDT\data2";
      libname data3 "\\SmithDT\data3";
      libname data4 "\\SmithDT\data4";
   %end;
%mend;
%allocate_libraries
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Substitute FOO and BAR with your desktop and laptop computer names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that you're running Base SAS (i.e. DMS) on both machines.&amp;nbsp; If you're running EG, then COMPUTERNAME would be the name of the server.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 04:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/565742#M158886</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-06-13T04:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566280#M159111</link>
      <description>&lt;P&gt;I don't want to add confusion but you may want to be careful using the phrase "concatenated libname" as in your subject line as that sounds like you want to concatenate libraries, i.e. reference multiple storage areas with a single library name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The libname does that by something such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname all (&amp;nbsp;"d:\data1"&amp;nbsp;&amp;nbsp;"d:\data2" &amp;nbsp;"d:\data3" &amp;nbsp;"d:\data4");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not a good idea if you have multiple data sets with the same name but can be useful to reference data sets stored in separate locations without having to keep track of which set is in which library.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 20:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566280#M159111</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-14T20:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566300#M159127</link>
      <description>Thanks, you're right, I didn't mean to concatenate the libname but&lt;BR /&gt;concatenate the, well, I don't know what it could be called, the&lt;BR /&gt;actual library name, like you do a character variable.&lt;BR /&gt;&lt;BR /&gt;but actually, that may do what I wanted:&lt;BR /&gt;&lt;BR /&gt;libname test ("\\Desktop\data" "d:\data\");&lt;BR /&gt;&lt;BR /&gt;If that were on the laptop with access to the network, then it would&lt;BR /&gt;go to the Desktop via the network, but if it did not have access to&lt;BR /&gt;the network, then it would go to the second choice.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Hi Bahr,&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;ballardw (Super User) posted a new reply in&lt;BR /&gt;&amp;gt;SAS&lt;BR /&gt;&amp;gt;Programming on 06-14-2019 04:19 PM :&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;----------&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Re:&lt;BR /&gt;&amp;gt;Creating a concatenated Libname using a macro (%let)&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;I don't want to add confusion but you may want to be careful using&lt;BR /&gt;&amp;gt;the phrase "concatenated libname" as in your subject line as that&lt;BR /&gt;&amp;gt;sounds like you want to concatenate libraries, i.e. reference&lt;BR /&gt;&amp;gt;multiple storage areas with a single library name.&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Â&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;The libname does that by something such as&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Â&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;libname all (Â "d:\data1"Â Â "d:\data2" Â "d:\data3" Â "d:\data4");&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Â&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Not a good idea if you have multiple data sets with the same name&lt;BR /&gt;&amp;gt;but can be useful to reference data sets stored in separate&lt;BR /&gt;&amp;gt;locations without having to keep track of which set is in which library.&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Reply&lt;BR /&gt;&amp;gt;|&lt;BR /&gt;&amp;gt;Accept&lt;BR /&gt;&amp;gt;as Solution |&lt;BR /&gt;&amp;gt;Like&lt;BR /&gt;&amp;gt;this message&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;----------&lt;BR /&gt;&amp;gt;SAS Support Communities sent this message to&lt;BR /&gt;&amp;gt;bahr.weiss@gmail.com.&lt;BR /&gt;&amp;gt;You are receiving this email because a new message matches your&lt;BR /&gt;&amp;gt;subscription to a topic.&lt;BR /&gt;&amp;gt;To control which emails we send you please go to,&lt;BR /&gt;&amp;gt;manage&lt;BR /&gt;&amp;gt;your subscription&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Jun 2019 21:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566300#M159127</guid>
      <dc:creator>Bahr</dc:creator>
      <dc:date>2019-06-14T21:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566302#M159129</link>
      <description>Wow, that was simple but exactly what I wanted, thanks very much.&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Jun 2019 21:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566302#M159129</guid>
      <dc:creator>Bahr</dc:creator>
      <dc:date>2019-06-14T21:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566324#M159144</link>
      <description>Thanks, actually I have three different ways to do it, all of which&lt;BR /&gt;are very interesting for other reasons as well. I didn't know about&lt;BR /&gt;the =%sysget(COMPUTERNAME) thing, which is interesting for several&lt;BR /&gt;reasons (it can create an indicator in the Log which computer was&lt;BR /&gt;being used). Thanks again.&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Jun 2019 23:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566324#M159144</guid>
      <dc:creator>Bahr</dc:creator>
      <dc:date>2019-06-14T23:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566343#M159150</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277708"&gt;@Bahr&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;but actually, that may do what I wanted:&lt;BR /&gt;&lt;BR /&gt;libname test ("\\Desktop\data" "d:\data\");&lt;BR /&gt;&lt;BR /&gt;If that were on the laptop with access to the network, then it would&lt;BR /&gt;go to the Desktop via the network, but if it did not have access to&lt;BR /&gt;the network, then it would go to the second choice.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277708"&gt;@Bahr&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's not going to work.&amp;nbsp;If one of the paths is invalid then the libname will throw an error.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2019 01:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566343#M159150</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-06-15T01:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566362#M159158</link>
      <description>Actually, on my version of SAS it generates a warning but not an&lt;BR /&gt;error, and writes to the first sub-directory that is valid.&lt;BR /&gt;&lt;BR /&gt;810 libname test ('d:\data\Recap III' 'd:\data\recap');&lt;BR /&gt;WARNING: One or more libraries specified in the concatenated library&lt;BR /&gt;TEST do not exist. These libraries were removed from the concatenation.&lt;BR /&gt;NOTE: Libref TEST was successfully assigned as follows:&lt;BR /&gt;Levels: 1&lt;BR /&gt;Engine(1): V9&lt;BR /&gt;Physical Name(1): d:\data\recap&lt;BR /&gt;811 data test.temp;x=1;run;&lt;BR /&gt;&lt;BR /&gt;NOTE: The data set TEST.TEMP has 1 observations and 1 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;812 proc contents data=test.temp;run;&lt;BR /&gt;&lt;BR /&gt;NOTE: PROCEDURE CONTENTS used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 15 Jun 2019 13:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566362#M159158</guid>
      <dc:creator>Bahr</dc:creator>
      <dc:date>2019-06-15T13:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566487#M159215</link>
      <description>&lt;P&gt;Thanks everyone for all of the very interesting solutions.&amp;nbsp; They were useful not only for this particular issue but also for better understanding of the libname command and the %let macro.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 03:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566487#M159215</guid>
      <dc:creator>Bahr</dc:creator>
      <dc:date>2019-06-17T03:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a concatenated Libname using a macro (%let)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566488#M159216</link>
      <description>&lt;P&gt;thanks, I hadn't realized that yet.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 03:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-concatenated-Libname-using-a-macro-let/m-p/566488#M159216</guid>
      <dc:creator>Bahr</dc:creator>
      <dc:date>2019-06-17T03:16:49Z</dc:date>
    </item>
  </channel>
</rss>

