<?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: Loop through multiple libraries in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904873#M357464</link>
    <description>&lt;P&gt;You say LIBRARIES in your subject line.&amp;nbsp; But in your text you appear to be talking about directories.&lt;/P&gt;
&lt;P&gt;Do you have libref's defined that point to each of those directories?&lt;/P&gt;
&lt;P&gt;Are you talking about SAS datasets in those different directories?&amp;nbsp; What are the names of the datasets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have datasets in many different directories sometimes it is easier to use the actual physical name of the dataset file instead of going to the trouble of defining a series of librefs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_2023;
  set "/xxx/202301/somedata.sas7bdat"
      "/xxx/202302/somedata.sas7bdat"
      "/xxx/202303/somedata.sas7bdat"
      "/xxx/202304/somedata.sas7bdat"
      "/xxx/202305/somedata.sas7bdat"
      "/xxx/202306/somedata.sas7bdat"
      "/xxx/202307/somedata.sas7bdat"
      "/xxx/202308/somedata.sas7bdat"
      "/xxx/202309/somedata.sas7bdat"
      "/xxx/202310/somedata.sas7bdat"
      "/xxx/202311/somedata.sas7bdat"
      "/xxx/202312/somedata.sas7bdat"
  ;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If there is a PATTERN to the names of the directories then you can use code to generate the directory names.&amp;nbsp; For example if you wanted to generate the six digit string representing months in YYYYMM style then you could use a DO loop like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;basedate = '01JAN2023'd;
do offset=0 to 11 ;
  date = intnx('month',basedate,offset);
  yymm = put(date,yymmn6.);
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which if you needed that in macro code might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let basedate = '01JAN2023'd;
%do offset=0 %to 11 ;
  %let date = %sysfunc(intnx(month,&amp;amp;basedate,&amp;amp;offset));
  %let yymm = %sysfunc(putn(&amp;amp;date,yymmn6.));
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 28 Nov 2023 15:12:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-11-28T15:12:15Z</dc:date>
    <item>
      <title>Loop through multiple libraries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904802#M357451</link>
      <description>Wonder if any experts can help.&lt;BR /&gt;I have hundreds of libraries with databases of same names in each library. My libraries are organized by dates for each month each year, such as /xxx/202301, /xxx/202302 etc.&lt;BR /&gt;what I need is to run a simple query against some databases within each library, but have to loop through all libraries of my choice to get data statistics. I wonder if there is a way to use a variable to do the loop, and then associate the variable with the library names.&lt;BR /&gt;&lt;BR /&gt;Thanks much for your expert advice!</description>
      <pubDate>Tue, 28 Nov 2023 09:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904802#M357451</guid>
      <dc:creator>Linzhang426</dc:creator>
      <dc:date>2023-11-28T09:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through multiple libraries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904804#M357452</link>
      <description>&lt;P&gt;What do you mean by a "database" - do you mean a single SAS dataset , or a group of datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you mean single dataset. Does the dataset has one common name? Or are they different?&lt;/P&gt;
&lt;P&gt;[EDIT:] Does the "xxx" means one common root directory ?&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 09:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904804#M357452</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-11-28T09:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through multiple libraries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904814#M357457</link>
      <description>&lt;P&gt;Do you need to combine source data and run the analysis once, or run the complete analysis for each library, with separate results?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 11:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904814#M357457</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-28T11:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through multiple libraries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904873#M357464</link>
      <description>&lt;P&gt;You say LIBRARIES in your subject line.&amp;nbsp; But in your text you appear to be talking about directories.&lt;/P&gt;
&lt;P&gt;Do you have libref's defined that point to each of those directories?&lt;/P&gt;
&lt;P&gt;Are you talking about SAS datasets in those different directories?&amp;nbsp; What are the names of the datasets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have datasets in many different directories sometimes it is easier to use the actual physical name of the dataset file instead of going to the trouble of defining a series of librefs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_2023;
  set "/xxx/202301/somedata.sas7bdat"
      "/xxx/202302/somedata.sas7bdat"
      "/xxx/202303/somedata.sas7bdat"
      "/xxx/202304/somedata.sas7bdat"
      "/xxx/202305/somedata.sas7bdat"
      "/xxx/202306/somedata.sas7bdat"
      "/xxx/202307/somedata.sas7bdat"
      "/xxx/202308/somedata.sas7bdat"
      "/xxx/202309/somedata.sas7bdat"
      "/xxx/202310/somedata.sas7bdat"
      "/xxx/202311/somedata.sas7bdat"
      "/xxx/202312/somedata.sas7bdat"
  ;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If there is a PATTERN to the names of the directories then you can use code to generate the directory names.&amp;nbsp; For example if you wanted to generate the six digit string representing months in YYYYMM style then you could use a DO loop like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;basedate = '01JAN2023'd;
do offset=0 to 11 ;
  date = intnx('month',basedate,offset);
  yymm = put(date,yymmn6.);
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which if you needed that in macro code might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let basedate = '01JAN2023'd;
%do offset=0 %to 11 ;
  %let date = %sysfunc(intnx(month,&amp;amp;basedate,&amp;amp;offset));
  %let yymm = %sysfunc(putn(&amp;amp;date,yymmn6.));
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2023 15:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-multiple-libraries/m-p/904873#M357464</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-28T15:12:15Z</dc:date>
    </item>
  </channel>
</rss>

