<?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 Find the table whose name has the latest date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553142#M153788</link>
    <description>&lt;P&gt;This is what I have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname tables "c:\Data";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the libname "tables" I have many tables looking like this (this is just part of all the tables, there are at least a 100 more with the same name format)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result_201103_credit&lt;/P&gt;&lt;P&gt;result_201106_credit&lt;/P&gt;&lt;P&gt;result_201109_credit&lt;/P&gt;&lt;P&gt;result_201112_credit&lt;/P&gt;&lt;P&gt;result_201903_credit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write a sas code that extracts the latest date and turns it into a macro variable. So when I write&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;date.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it returns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;201903&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Apr 2019 07:48:09 GMT</pubDate>
    <dc:creator>rhapsody</dc:creator>
    <dc:date>2019-04-23T07:48:09Z</dc:date>
    <item>
      <title>Find the table whose name has the latest date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553142#M153788</link>
      <description>&lt;P&gt;This is what I have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname tables "c:\Data";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the libname "tables" I have many tables looking like this (this is just part of all the tables, there are at least a 100 more with the same name format)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result_201103_credit&lt;/P&gt;&lt;P&gt;result_201106_credit&lt;/P&gt;&lt;P&gt;result_201109_credit&lt;/P&gt;&lt;P&gt;result_201112_credit&lt;/P&gt;&lt;P&gt;result_201903_credit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write a sas code that extracts the latest date and turns it into a macro variable. So when I write&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;date.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it returns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;201903&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 07:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553142#M153788</guid>
      <dc:creator>rhapsody</dc:creator>
      <dc:date>2019-04-23T07:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Find the table whose name has the latest date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553147#M153789</link>
      <description>&lt;P&gt;Consider that you have the library tables, then you can try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as select memname from dictionary.tables where libname='TABLES';
quit;


proc sql;
select max(input(scan(memname,2,'_'),best.)) as memname2 into: date from table ;
quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;date;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2019 08:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553147#M153789</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-04-23T08:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find the table whose name has the latest date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553148#M153790</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* example data */
data 
  result_201103_credit
  result_201106_credit
  result_201109_credit
  result_201112_credit
  result_201903_credit
;
x = 42;
run;

libname tables (work);

/* get the dataset names */
proc contents 
  data = tables._all_
  memtype = DATA
  OUT=SAS_data_set(keep = memname where=(memname like 'RESULT%CREDIT')) /* names are "upcassed" */
;
run;

/* keep only digits in names and get the max value */
proc sql;
  select 
    max(compress(memname, , "KD"))
  into 
    :date trimmed
  from 
    SAS_data_set
  ;
quit;

%put *&amp;amp;date.*;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 09:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553148#M153790</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-04-23T09:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find the table whose name has the latest date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553151#M153791</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248575"&gt;@rhapsody&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could write a macro to give the wanted result. The code is based on the good advices you have got so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getlasttable;
	%if not %symexist(date) %then %global date;
	%let date =;
	proc sql noprint;
			select max(scan(memname,2,'_')) into :date
			from dictionary.tables
			where 
				libname = upcase("tables")
				and memname like 'RESULT%CREDIT';
	quit;
%mend;

%getlasttable;
%put &amp;amp;=date;

201903&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 09:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/553151#M153791</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-04-23T09:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Find the table whose name has the latest date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/554608#M154302</link>
      <description>There is a paper that you might find useful : Automate in a Dash with SAS: Time saving techniques for building quality improvement dashboards. Starts by capturing all file names from a folder and getting the latest named file.&lt;BR /&gt;Hope it helps&lt;BR /&gt;</description>
      <pubDate>Sun, 28 Apr 2019 17:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-table-whose-name-has-the-latest-date/m-p/554608#M154302</guid>
      <dc:creator>dario_medina</dc:creator>
      <dc:date>2019-04-28T17:53:09Z</dc:date>
    </item>
  </channel>
</rss>

