<?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: use macro to change library names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347199#M80159</link>
    <description>&lt;P&gt;In that process, remove those from all the libnames from your programs and put them in one master program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may as well refactor an inefficient process while you're at it.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Apr 2017 22:33:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-04-04T22:33:07Z</dc:date>
    <item>
      <title>use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347178#M80153</link>
      <description>&lt;P&gt;I have a program that includes 20 + sas code files. For each one I need to open the file, change the library names, replace those old library names with my own library names.&lt;/P&gt;
&lt;P&gt;Since it is mainly to copy and paste, I would like to get advice from you on how to replace.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, the old library names are listed below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname ou1 '/c/Data';&lt;/P&gt;
&lt;P&gt;libname oud1 '/c/Data/sap';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to cross out these two lines and replace them with&lt;/P&gt;
&lt;P&gt;libname ou1 '/c/Data/ini';&lt;/P&gt;
&lt;P&gt;libname oud1 '/c/Data/ini/sap';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any advice to do it with sas macro, since I need to copy and paste 20 more times? And how to save it in a library? Or any other way to do it more efficiently? Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 20:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347178#M80153</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-04-04T20:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347182#M80154</link>
      <description>&lt;P&gt;If that's a once off task and you need to replace exactly the same paths then what I would do is to open all the 20+ .sas files with Notepad++ and use&amp;nbsp;"Replace All in All Opened Documents".&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 21:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347182#M80154</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-04T21:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347199#M80159</link>
      <description>&lt;P&gt;In that process, remove those from all the libnames from your programs and put them in one master program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may as well refactor an inefficient process while you're at it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 22:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347199#M80159</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-04T22:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347342#M80203</link>
      <description>&lt;P&gt;That is a good idea. I will try.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 13:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347342#M80203</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-04-05T13:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347343#M80204</link>
      <description>&lt;P&gt;That is what I am thinking but I do not know how to write the code.. Can you provide code? Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 13:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347343#M80204</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-04-05T13:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347352#M80208</link>
      <description>&lt;P&gt;It's unclear who you're responding to but it literally means moving the library statements from their programs to a single program.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to determine if that would streamline your issues and if this would make things easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're doing rsubmits (server) work then it may not be possible.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 13:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347352#M80208</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-05T13:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347363#M80215</link>
      <description>&lt;P&gt;Sorry if I had not made it clear. I was replying to your post. Would you please share you code? I believe it would be easier.Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 14:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347363#M80215</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-04-05T14:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347531#M80294</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40773"&gt;@Bal23&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;There are multiple ways of doing what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;proposes but it all boils down to not have fully qualified paths in your source code so you don't run into the issue you're having right now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One approach you could take:&lt;/P&gt;
&lt;P&gt;1. Have a macro variable with the root path somewhere centrally defined (i.e. autoexec or &amp;nbsp;startup code in EG or first %include of an "init.sas" when you run your programs)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dataRoot=/c/Data;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Use this macro variable as part of your paths in any subsequent code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname ou1 "&amp;amp;dataRoot";
libname oud1 "&amp;amp;dataRoot/sap";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now if the root path changes you only need to change it in a single place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/c/data doesn't sound like but if you work in a commercial environment then issue a &lt;EM&gt;%put _all_;&lt;/EM&gt; statement. There is a chance that some SAS Admin already created and maintains such a global macro variable.&lt;/P&gt;
&lt;P&gt;IF this is in a commercial environment and they had to change the data folder path which will affect a lot of users then I'd also ask the question if it wouldn't be possible to implement a symbolic link with the old pathname so no code changes are required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And last but not least:&lt;/P&gt;
&lt;P&gt;For libnames which get used in many programs and/or by multiple users SAS best practice is to define these in SAS Metadata. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 22:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347531#M80294</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-05T22:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347870#M80459</link>
      <description>&lt;P&gt;Thank you. Before I do this, my understanding is, I should either cross out the original paths or replace with blank, as you suggest on your first post. Do I understand correctly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 18:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347870#M80459</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-04-06T18:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: use macro to change library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347871#M80460</link>
      <description>&lt;P&gt;Or, can I create another two macros, to replace these two statments wtih blank so that I need not open each one, cross out, or delete?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 18:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-macro-to-change-library-names/m-p/347871#M80460</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-04-06T18:36:12Z</dc:date>
    </item>
  </channel>
</rss>

