<?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 to write generic libname to multiple databases? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374120#M89522</link>
    <description>wow, thank you, but lot more work than I thought. my initial reaction is to get back to exhaustive iterations.</description>
    <pubDate>Fri, 07 Jul 2017 23:16:22 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2017-07-07T23:16:22Z</dc:date>
    <item>
      <title>How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374117#M89519</link>
      <description>&lt;P&gt;I'd like to stack 20 different datasets in data step. They have common libname. How to specify common libname for 20 or more different datasets? to execute concantenation as shown below? &amp;nbsp;Listing libname for each dataset would become quite tedious task. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data libname2.want; set libname2(com2011Jan16 through com2017Feb29);&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I appreciate your time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 22:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374117#M89519</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-07T22:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374118#M89520</link>
      <description>&lt;P&gt;Hi, if it's all the data sets in that library, here's an example ...&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;libname z 'z:\';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data z.one;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;retain x 10;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data z.two;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;retain x 10;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* concatenate the data set names into a macro variable;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;select catt('z.',memname) into :dsets separated by ' '&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;from dictionary.tables where libname = 'Z';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data new;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set &amp;amp;dsets;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;If your data sets had a common numeric suffix, it's easier ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data z.d1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;retain x 10;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data z.d2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;retain x 10;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data new;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set z.d1-z.d2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 23:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374118#M89520</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2017-07-07T23:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374119#M89521</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_tables(start=19991231,end=19991231);
  %local daten suffix i; 
  %let daten=%sysfunc(inputn(&amp;amp;start,yymmdd8.));
  %do %while(&amp;amp;daten&amp;lt;=%sysfunc(inputn(&amp;amp;end,yymmdd8.)));
    %let suffix=%sysfunc(putn(&amp;amp;daten,yymon7.))%sysfunc(day(&amp;amp;daten));
LIBNAME2.COM&amp;amp;suffix
    %let daten=%sysfunc(intnx(day,&amp;amp;daten,1));
  %end;
%mend;
                              
data libname2.want; 
  set %list_tables(start=20160128,end=20160203); 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;set LIBNAME2.COM2016JAN28 LIBNAME2.COM2016JAN29 LIBNAME2.COM2016JAN30 LIBNAME2.COM2016JAN31&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;LIBNAME2.COM2016FEB1 LIBNAME2.COM2016FEB2 LIBNAME2.COM2016FEB3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;You are asking for trouble with these suffixes.&lt;/P&gt;
&lt;P&gt;20171231 will be easier to manage in the long run.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 23:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374119#M89521</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-07T23:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374120#M89522</link>
      <description>wow, thank you, but lot more work than I thought. my initial reaction is to get back to exhaustive iterations.</description>
      <pubDate>Fri, 07 Jul 2017 23:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374120#M89522</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-07T23:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374121#M89523</link>
      <description>goodness gracious. i'd simply list the libname 20 times for each datasets &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 07 Jul 2017 23:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374121#M89523</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-07T23:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374124#M89525</link>
      <description>&lt;P&gt;Maybe this is what you want then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;FONT face="courier new,courier"&gt;set LIBNAME2.COM2016JAN16-LIBNAME2.COM2016JAN31 &amp;nbsp; LIBNAME2.COM2016FEB:&amp;nbsp; ;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 23:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374124#M89525</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-07T23:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374127#M89527</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;May be we just all missunderstand what you're really dealing with and you need to provide additional&amp;nbsp;information first. Let me ask you a few questions to give you an idea what we probably need to know to better understand your situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Are these SAS tables or tables in one or multiple databases/database schemas?&lt;/P&gt;
&lt;P&gt;2. Do the tables all have the same structure (same column names with the same attributes like type, lenght, format...)?&lt;/P&gt;
&lt;P&gt;3. If SAS tables: Are these tables stored in a single folder or in multiple folders?&lt;/P&gt;
&lt;P&gt;4. If SAS tables in multiple folders:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; a) Are the names of these SAS tables&amp;nbsp;identical or do they differ&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; b) If the names are different: Do the names follow some naming convention and if yes, what's the naming convention&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 00:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374127#M89527</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-07-08T00:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374280#M89608</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm dealing with multiple databases with same exact column names with the same attributes like type, lenght, format. It's a hospital discharge data periodically updated. Each update is output to separate sas data and stored in the single folder. Datasets are labeled to contain constant initials followed with date when created.&lt;/P&gt;&lt;P&gt;i.e.&lt;/P&gt;&lt;P&gt;maggiechildren2017Jun23&lt;/P&gt;&lt;P&gt;maggiechildren2012Jan11&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; set home.(maggiechildren:);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried as shown in the code taking advantage of initial part of the name they all share with no success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for asking for a clarification.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 16:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374280#M89608</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-09T16:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to write generic libname to multiple databases?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374330#M89623</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Looks to me like you're almost there and it's just about using correct SAS syntax - remove the bracket around the SAS table name.&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; home&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;maggiechildren:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here some working sample code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* libname to folder where "maggiechildren:" ds are stored */
libname home (work);&lt;BR /&gt;/* libname home '&amp;lt;path to your SAS folder&amp;gt;'; */

/* prepare test data */
data 
  maggiechildren2017Jun23
  maggiechildren2012Jan11
  ;
  set sashelp.class;
run;

/* read all maggiechildren into single table */
data want;
  length _sourceTable sourceTable $41;
  format data_date date9.;
  set home.maggiechildren: indsname=_sourceTable;
  sourceTable=_sourceTable;
  data_date=input(substr(_sourceTable,length(_sourceTable)-8),?? anydtdte.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Jul 2017 22:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-generic-libname-to-multiple-databases/m-p/374330#M89623</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-07-09T22:14:51Z</dc:date>
    </item>
  </channel>
</rss>

