<?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 find and use the most recent table based on the name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-and-use-the-most-recent-table-based-on-the-name/m-p/897509#M354664</link>
    <description>&lt;P&gt;Below should do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname toshare "%sysfunc(pathname(work))";
data 
  toshare.extdate_01apr2023
  toshare.extdate_01may2023
  toshare.extdate_01jun2023
  ;
  set sashelp.class;
run;

%let last_tbl_dt=;
proc sql noprint;
  select 
    max(input(scan(memname,-1,'_'),date9.)) format=date9.
      into :last_tbl_dt trimmed
  from dictionary.tables
  where 
    libname = 'TOSHARE'
    and memname like 'EXTDATE^_%' escape '^'
  ;
quit;

data want;
  set toshare.extdate_&amp;amp;last_tbl_dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Oct 2023 01:15:56 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-10-06T01:15:56Z</dc:date>
    <item>
      <title>How do i find and use the most recent table based on the name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-and-use-the-most-recent-table-based-on-the-name/m-p/897507#M354663</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do i scan a particular library to use the latest table based on their name.&amp;nbsp; In this example, library is toshare and tables all start with extdate_.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rngsh001_0-1696551358070.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88677i2EE77AF7BD82B665/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rngsh001_0-1696551358070.png" alt="rngsh001_0-1696551358070.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I found this macro from another post which works when date format is yyyymmdd, but not for ddmmmyyyy.&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%macro getlasttable;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%if not %symexist(date) %then %global date;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%let date =;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;select max(scan(memname,-1,'_')) into :date&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from my_contents&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;where&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;libname = upcase("toshare")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;and memname like 'EXTDATE_%';&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;/* format date ddmmmyyyy.;*/&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;%mend;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks for your help.&lt;/DIV&gt;</description>
      <pubDate>Fri, 06 Oct 2023 00:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-and-use-the-most-recent-table-based-on-the-name/m-p/897507#M354663</guid>
      <dc:creator>rngsh001</dc:creator>
      <dc:date>2023-10-06T00:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do i find and use the most recent table based on the name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-and-use-the-most-recent-table-based-on-the-name/m-p/897509#M354664</link>
      <description>&lt;P&gt;Below should do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname toshare "%sysfunc(pathname(work))";
data 
  toshare.extdate_01apr2023
  toshare.extdate_01may2023
  toshare.extdate_01jun2023
  ;
  set sashelp.class;
run;

%let last_tbl_dt=;
proc sql noprint;
  select 
    max(input(scan(memname,-1,'_'),date9.)) format=date9.
      into :last_tbl_dt trimmed
  from dictionary.tables
  where 
    libname = 'TOSHARE'
    and memname like 'EXTDATE^_%' escape '^'
  ;
quit;

data want;
  set toshare.extdate_&amp;amp;last_tbl_dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 01:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-and-use-the-most-recent-table-based-on-the-name/m-p/897509#M354664</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-06T01:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do i find and use the most recent table based on the name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-and-use-the-most-recent-table-based-on-the-name/m-p/897513#M354665</link>
      <description>Thanks Patrick, worked like a charm. Much appreciated.</description>
      <pubDate>Fri, 06 Oct 2023 01:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-and-use-the-most-recent-table-based-on-the-name/m-p/897513#M354665</guid>
      <dc:creator>rngsh001</dc:creator>
      <dc:date>2023-10-06T01:33:53Z</dc:date>
    </item>
  </channel>
</rss>

