<?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: Dynamic Libname creation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802693#M316016</link>
    <description>One libname for each folder because I want to traverse each folder and check for datasets. Each folder will have 500 of datasets</description>
    <pubDate>Thu, 17 Mar 2022 19:47:05 GMT</pubDate>
    <dc:creator>Nitish1003</dc:creator>
    <dc:date>2022-03-17T19:47:05Z</dc:date>
    <item>
      <title>Dynamic Libname creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802689#M316012</link>
      <description>Hello everyone,&lt;BR /&gt;Need one help with sas programming I have folder structure "201601" i.e. YYYYMM this is from year 2016 and still going on so for every month we create new folder for that particular year. Now I want to create libname for all the folders starting from 201601 to till date (I.e. 201601 to the month when the code is getting executed) Example of i am running the code for June 2022 the libname should be created from 201601 to 202206.&lt;BR /&gt;Any suggestions how can I achive it. Appreciate some help here</description>
      <pubDate>Thu, 17 Mar 2022 19:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802689#M316012</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2022-03-17T19:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Libname creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802690#M316013</link>
      <description>&lt;P&gt;Do you want one libname for each folder or a single libname that will reference all of the folders?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2022 19:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802690#M316013</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-17T19:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Libname creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802691#M316014</link>
      <description>&lt;P&gt;Do you have datasets of the same name in each of the monthly folders? If so a LIBNAME pointing at all folders won't work as you can't identify from which folder a particular dataset is required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If datasets have the same name in each of the monthly folders, a much better data model would be to add a suffix to each dataset name&amp;nbsp; - MyDataset_YYYYMM then move them all into one folder.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2022 19:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802691#M316014</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-03-17T19:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Libname creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802693#M316016</link>
      <description>One libname for each folder because I want to traverse each folder and check for datasets. Each folder will have 500 of datasets</description>
      <pubDate>Thu, 17 Mar 2022 19:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802693#M316016</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2022-03-17T19:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Libname creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802694#M316017</link>
      <description>Thanks for looking into it. The datasets name is in XYZ_yyyymm and moving all datasets to one folder is not possible</description>
      <pubDate>Thu, 17 Mar 2022 19:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802694#M316017</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2022-03-17T19:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Libname creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802701#M316024</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/87248"&gt;@Nitish1003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;One libname for each folder because I want to traverse each folder and check for datasets. Each folder will have 500 of datasets&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You didn't provide much to go on for building paths and nothing about the actual library name (libref).&lt;/P&gt;
&lt;P&gt;This data step lets you test specifying your basic path the part up to the YYYYMM into Libbase variable; a base for the libref in the Refbase variable.&lt;/P&gt;
&lt;P&gt;Then uses a loop over the months to create the path and libref. You can look at the data set however you like, print or viewer.&lt;/P&gt;
&lt;P&gt;Play with that until you get the text you want in the Libpath and Libref variables. You would then uncomment the line of code with Libname function call so that it executes and creates the libraries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   length libpath $ 200 refbase $ 2 libref $ 8;
   libbase ="C:\folder\subfolder";
   /* since you intend to have 6 characters YYYYMM
      as part of the libref value the base can 
      have at most 2 characters and CANNOT start with 
      digit
   */
   refbase ="M";
   date = mdy(1,1,2016);
   do while (date le intnx('month',today(),0,'B'));
      libpath = cats(libbase,put(date,yymmn6.));
      libref  = cats(refbase,put(date,yymmn6.));
      output;
   /* rc = libname(libref,libpath); */
      date = intnx('month',date,1,'B');
   end;
run;&lt;/PRE&gt;
&lt;P&gt;You do want to test this first. You may need to increase the length of the libpath if you have long paths.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2022 20:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802701#M316024</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-17T20:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Libname creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802705#M316028</link>
      <description>&lt;P&gt;I don't really see what value you are going to get from defining all of those librefs.&amp;nbsp; You could just reference the datasets directly by their physical filename (and let SAS define its own librefs that you can ignore).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
  set 
   "&amp;amp;topnode/201601/dataset1" 
   "&amp;amp;topnode/201602/dataset1" 
...
   "&amp;amp;topnode/202206/dataset1" 
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to generate 201601, 201602, .... 202206 then use the INTCK() and INTNX() functions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do offset=0 to intck('month','01JAN2016'd,'01JUN2022'd);
   date=intnx('month','01JAN2016'd,offset);
   string=put(date,yymmn6.);
   ....
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Mar 2022 20:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Libname-creation/m-p/802705#M316028</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-17T20:51:59Z</dc:date>
    </item>
  </channel>
</rss>

