<?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: How do I iteratively create multiple libnames using a do loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172652#M301688</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;libname mylib v9 ( '&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;C:\Users\desktop\folder\03212013' ,&amp;nbsp; 'C:\Users\desktop\folder\05052013'&amp;nbsp; ..............&lt;/SPAN&gt; )&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;But if there were a table located in multiple folds then the first fold 's table will be used .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Jul 2014 13:48:47 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2014-07-09T13:48:47Z</dc:date>
    <item>
      <title>How do I iteratively create multiple libnames using a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172651#M301687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a pathway with 80+ folders that I need to create a libname for each of the 80+ folders. I currently have a SAS dataset with the name of each of the folders. The names of the folders are the date they were generated (at various times over the past year; ex: 03212013, 05052013, 09022013, 12202014, etc).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I tell SAS to iteratively create a libname for each observation in this dataset? All of the 80+ folders are in the same folder (i.e. C:\Users\desktop\folder\03212013, C:\Users\desktop\folder\05052013, etc.)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 13:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172651#M301687</guid>
      <dc:creator>egarcia</dc:creator>
      <dc:date>2014-07-09T13:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I iteratively create multiple libnames using a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172652#M301688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;libname mylib v9 ( '&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;C:\Users\desktop\folder\03212013' ,&amp;nbsp; 'C:\Users\desktop\folder\05052013'&amp;nbsp; ..............&lt;/SPAN&gt; )&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;But if there were a table located in multiple folds then the first fold 's table will be used .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 13:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172652#M301688</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-07-09T13:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I iteratively create multiple libnames using a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172653#M301689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this macro (untested):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro libnames;&lt;BR /&gt;%let root='C:\Users\desktop\folder';&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; set list_of_folders(keep=folder_name) nobs=nobs;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* SAS Dataset containing the names of the folders */&lt;BR /&gt;&amp;nbsp; if _N_=1 then call symput("N_Libs",nobs);&lt;BR /&gt;&amp;nbsp; folder=cats("Folder",_N_);&lt;BR /&gt;&amp;nbsp; library=cats("Lib",_N_);&lt;BR /&gt;&amp;nbsp; lib_name=cats('L',substr(folder_name,1,4),substr(folder_name,7,2));&lt;BR /&gt;&amp;nbsp; call symput(folder,folder_name);&lt;BR /&gt;&amp;nbsp; call symput(library,lib_name);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%let i=1;&lt;BR /&gt;%do %while (&amp;amp;i &amp;lt;= &amp;amp;N_Libs)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; libname &amp;amp;&amp;amp;Lib&amp;amp;i "&amp;amp;root.\&amp;amp;&amp;amp;Folder&amp;amp;i";&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %let i= %eval(&amp;amp;i+1);&lt;BR /&gt;%end;&lt;BR /&gt;%mend libnames;&lt;BR /&gt;%libnames&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Data _null_ step creates the 80+ macrovariables containing the librefs (i.e. L032113, L050513, etc) and folder_names.&lt;/P&gt;&lt;P&gt; Hope this helps,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 14:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172653#M301689</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2014-07-09T14:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I iteratively create multiple libnames using a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172654#M301690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No need for macro code. Just use a data step and have it call the LIBNAME() function&lt;/P&gt;&lt;P&gt;You will need to define a libref for each one.&amp;nbsp; Either just generate the names sequentially or possibly use some part of the date for that.&lt;/P&gt;&lt;P&gt;Let's assume that you have a data set with the variable PATH that has the directories that you wan to define librefs for.&lt;/P&gt;&lt;P&gt;If you will only be reading from these folders then use the 'ACCESS=READONLY' option and SAS will prevent you from accidentally overwriting the existing files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set have ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; length libref $8 rc 8 sysmsg $200 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; libref = 'LIBR' || put(_n_,Z4.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; rc = libname(libref,path,,'access=readonly');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if rc ne 0 then sysmsg = sysmsg();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 14:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172654#M301690</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-07-09T14:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I iteratively create multiple libnames using a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172655#M301691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Excellent! A few small tweaks and it works perfectly. &lt;STRONG&gt;Thank you very much!&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Remove single quotes from macro variable root&lt;/P&gt;&lt;P&gt;2. Add semicolon after %do %while&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 14:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172655#M301691</guid>
      <dc:creator>egarcia</dc:creator>
      <dc:date>2014-07-09T14:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I iteratively create multiple libnames using a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172656#M301692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This works just as well. Thank you all very much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 15:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-iteratively-create-multiple-libnames-using-a-do-loop/m-p/172656#M301692</guid>
      <dc:creator>egarcia</dc:creator>
      <dc:date>2014-07-09T15:22:38Z</dc:date>
    </item>
  </channel>
</rss>

