<?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 loop through tables in a library in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764781#M39428</link>
    <description>&lt;P&gt;Code seems to be working fine. There just aren't any such datasets to find.&lt;/P&gt;</description>
    <pubDate>Mon, 30 Aug 2021 04:02:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-08-30T04:02:30Z</dc:date>
    <item>
      <title>How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764720#M39417</link>
      <description>How to loop through tables in a library (eg work) and find the table with largest date.&lt;BR /&gt;&lt;BR /&gt;Eg cust1aug2021&lt;BR /&gt;Cust2aug2021&lt;BR /&gt;Cust3aug2021&lt;BR /&gt;&lt;BR /&gt;I am trying to create a data step that use set cust3aug2021.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Sun, 29 Aug 2021 15:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764720#M39417</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-08-29T15:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764725#M39418</link>
      <description>&lt;P&gt;What is the variable that has the DATE?&amp;nbsp; What is the type (CHAR or NUM) of the variable?&amp;nbsp; Does it have a FORMAT attached to it?&amp;nbsp; What is the format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are the structures the same for all three tables?&lt;/P&gt;
&lt;P&gt;Or at least is the variable name that you want to use the same in each of them?&amp;nbsp; Does it have the same type? Same type of content?&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 15:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764725#M39418</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-29T15:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764738#M39419</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the dictionary tables and look for the table with the highest&amp;nbsp;&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;crdate (Date Created) or&lt;/LI&gt;
&lt;LI&gt;modate (Date Modified)&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL noprint;
 create table work.tt as
 select * 
 from dictionary.tables
 where libname="WORK"  
; QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 17:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764738#M39419</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-08-29T17:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764749#M39420</link>
      <description>&lt;P&gt;When putting timestamps in dataset or other filenames, do not (as in&amp;nbsp;&lt;STRONG&gt;NOT&lt;/STRONG&gt;) use such a stupid format. Use purely numeric dates in YMD order.&lt;/P&gt;
&lt;P&gt;I use "stupid" here because such dates do not sort correctly.&lt;/P&gt;
&lt;P&gt;Once you have a usable timestamp in your dataset name like&lt;/P&gt;
&lt;PRE&gt;cust20210801&lt;/PRE&gt;
&lt;P&gt;then you just pick the "highest" name, like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
selec max(memname) into :dsname
from dictionary tables
where libname  = "WORK" and memname like 'CUST%';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With the useless names you currently&amp;nbsp; have, you need to first read all names, extract the date portion, convert it to a SAS date value, and store that in a variable so you can sort by it.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 18:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764749#M39420</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-29T18:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764763#M39421</link>
      <description>Sorry, have relooked this again and the tables are currently named as such. Have tried to used the suggested codes but not much luck. Perhaps the naming is not good enough?&lt;BR /&gt;&lt;BR /&gt;cust_04JUL2019&lt;BR /&gt;cust_05FEB2020&lt;BR /&gt;&lt;BR /&gt;etc</description>
      <pubDate>Sun, 29 Aug 2021 20:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764763#M39421</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-08-29T20:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764764#M39422</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table tables as
select memname, input(scan(memname,2,'_'),date9.) as date
from dictionary.tables
where memname like 'CUST%';
select memname into :dsname
from tables
having date = max(date);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Aug 2021 21:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764764#M39422</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-29T21:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764771#M39423</link>
      <description>Sorry to keep coming back to this one. Have given the code a run but all dates are missing.&lt;BR /&gt;&lt;BR /&gt;The library these cust tables are in a library (e.g. abcd), do I need to code this in?&lt;BR /&gt;&lt;BR /&gt;memname	date&lt;BR /&gt;cust	.&lt;BR /&gt;cust	.&lt;BR /&gt;cust	.&lt;BR /&gt;cust_02AUG2021	.&lt;BR /&gt;cust_04AUG2020	.&lt;BR /&gt;cust_04JUL2019	.&lt;BR /&gt;cust_05FEB2020	.&lt;BR /&gt;cust_05MAR2021	.&lt;BR /&gt;&lt;BR /&gt;Code&lt;BR /&gt;roc sql noprint;&lt;BR /&gt;create table tables as&lt;BR /&gt;select memname, input(scan(memname,2,'_'),date9.) as date&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where memname like 'cust%';&lt;BR /&gt;select memname into :dsname&lt;BR /&gt;from tables&lt;BR /&gt;having date = max(date);&lt;BR /&gt;quit;</description>
      <pubDate>Sun, 29 Aug 2021 23:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764771#M39423</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-08-29T23:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764772#M39424</link>
      <description>&lt;P&gt;That code cannot work.&amp;nbsp; The values of MEMNAME are going to always be in UPPERCASE.&lt;/P&gt;
&lt;P&gt;Also what LIBREF did you define to point to where the datasets are?&lt;/P&gt;
&lt;P&gt;Let's assume the libref is named MYLIB&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table tables as
  select libname
       , memname
       , input(scan(memname,-1,'_'),?date11.) as date format=date9.
  from dictionary.tables
  where libname='MYLIB'
    and memname like 'CUST^_%' escape '^'
;
%put Found &amp;amp;sqlobs datasets in MYLIB whose names start with CUST_.;
select catx('.',libname,memname) into :dsname trimmed
  from tables
  having date = max(date)
;
%put The dataset with the largest date on the end of its name is &amp;amp;dsname..;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Aug 2021 23:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764772#M39424</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-29T23:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764776#M39425</link>
      <description>Thanks Tom. The tables are like below. The library name is SDLAB.&lt;BR /&gt;&lt;BR /&gt;CUST_20DEC2020&lt;BR /&gt;CUST_17JUL2019&lt;BR /&gt;&lt;BR /&gt;Have tried code below, but no luck &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;create table tables as&lt;BR /&gt;  select libname&lt;BR /&gt;       , memname&lt;BR /&gt;       , input(scan(memname,-1,'_'),?date11.) as date format=date9.&lt;BR /&gt;  from dictionary.tables&lt;BR /&gt;  where libname='SDLAB'&lt;BR /&gt;    and memname like 'CUST^_%' escape '^'&lt;BR /&gt;;&lt;BR /&gt;%put Found &amp;amp;sqlobs datasets in SDLAB whose names start with CUST_.;&lt;BR /&gt;select catx('.',libname,memname) into :dsname trimmed&lt;BR /&gt;  from tables&lt;BR /&gt;  having date = max(date)&lt;BR /&gt;;&lt;BR /&gt;%put The dataset with the largest date on the end of its name is &amp;amp;dsname..;&lt;BR /&gt;quit;&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Aug 2021 00:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764776#M39425</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-08-30T00:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764778#M39426</link>
      <description>&lt;P&gt;Are you sure the SDLIB libref is defined?&amp;nbsp; What ENGINE is it using?&lt;/P&gt;
&lt;P&gt;The code works fine for me:&lt;/P&gt;
&lt;PRE&gt;1     data CUST_20DEC2020 CUST_17JUL2019 ;
2     run;

NOTE: The data set WORK.CUST_20DEC2020 has 1 observations and 0 variables.
NOTE: The data set WORK.CUST_17JUL2019 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.03 seconds


3     proc sql noprint;
4     create table tables as
5       select libname
6            , memname
7            , input(scan(memname,-1,'_'),?date11.) as date format=date9.
8       from dictionary.tables
9       where libname='WORK'
10      and memname like 'CUST^_%' escape '^'
11    ;
NOTE: Table WORK.TABLES created, with 2 rows and 3 columns.

12    %put Found &amp;amp;sqlobs datasets in WORK whose names start with CUST_.;
Found 2 datasets in WORK whose names start with CUST_.
13    select catx('.',libname,memname) into :dsname trimmed
14      from tables
15      having date = max(date)
16    ;
NOTE: The query requires remerging summary statistics back with the original data.
17    %put The dataset with the largest date on the end of its name is &amp;amp;dsname..;
The dataset with the largest date on the end of its name is WORK.CUST_20DEC2020.
18    quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.06 seconds
      cpu time            0.03 seconds
&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Aug 2021 01:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764778#M39426</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-30T01:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764780#M39427</link>
      <description>27         proc sql noprint;&lt;BR /&gt;28         create table tables as&lt;BR /&gt;29           select libname&lt;BR /&gt;30                , memname&lt;BR /&gt;31                , input(scan(memname,-1,'_'),?date11.) as date format=date9.&lt;BR /&gt;32           from dictionary.tables&lt;BR /&gt;33           where libname='SDLAB'&lt;BR /&gt;34             and memname like 'CUST^_%' escape '^'&lt;BR /&gt;35         ;&lt;BR /&gt;NOTE: Table WORK.TABLES created, with 0 rows and 3 columns.&lt;BR /&gt;&lt;BR /&gt;36         %put Found &amp;amp;sqlobs datasets in SDLAB whose names start with CUST_.;&lt;BR /&gt;Found 0 datasets in SDLAB whose names start with CUST_.&lt;BR /&gt;37         select catx('.',libname,memname) into :dsname trimmed&lt;BR /&gt;38           from tables&lt;BR /&gt;39           having date = max(date)&lt;BR /&gt;40         ;&lt;BR /&gt;NOTE: The query requires remerging summary statistics back with the original data.&lt;BR /&gt;NOTE: No rows were selected.&lt;BR /&gt;41         %put The dataset with the largest date on the end of its name is &amp;amp;dsname..;&lt;BR /&gt;The dataset with the largest date on the end of its name is CUST              .&lt;BR /&gt;42         quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;      real time           0.01 seconds&lt;BR /&gt;      cpu time            0.02 seconds&lt;BR /&gt;      &lt;BR /&gt;</description>
      <pubDate>Mon, 30 Aug 2021 03:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764780#M39427</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-08-30T03:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764781#M39428</link>
      <description>&lt;P&gt;Code seems to be working fine. There just aren't any such datasets to find.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 04:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764781#M39428</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-30T04:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764783#M39429</link>
      <description>&lt;P&gt;Dumb question - did you assign the data library SDLAB before running this? I tried&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;'s code and it works fine.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 04:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764783#M39429</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-08-30T04:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop through tables in a library</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764784#M39430</link>
      <description>&lt;P&gt;You need to pay attention to details. DICTIONARY tables will always have the libnames and memnames in uppercase for SAS libraries and datasets.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 05:20:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-loop-through-tables-in-a-library/m-p/764784#M39430</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-30T05:20:29Z</dc:date>
    </item>
  </channel>
</rss>

