<?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: Look for the latest table available in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487242#M126935</link>
    <description>&lt;P&gt;1. SAS will sort the data for you when you read all tables.&lt;/P&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ACCOUNTS_180720      
     ACCOUNTS_180727
     ACCOUNTS_180815
     ACCOUNTS_170811  ;
run;
data _null_;
  set ACCOUNTS_1: (obs=1) indsname=INDSNAME end=LASTOBS;
  if LASTOBS then call symput('lastest_period',scan(INDSNAME,2,'_'));
run;
%put &amp;amp;=lastest_period;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;LASTEST_PERIOD=180815&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;2. I disagree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;'s sweeping statement.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; Having one large master dataset with a column for date means simpler faster access to the data.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Large tables can be&amp;nbsp;extremely&amp;nbsp;slow to access, and the most recent data -which only represent a fraction of all the data- is the most often used. In this (very common) case, it makes a lot of sense to use the structure detailed here. When needed, accessing all the data sets in one go is a matter a creating a view.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. In any case, these tables&amp;nbsp;should&amp;nbsp;indeed&amp;nbsp;contain&amp;nbsp;a PERIOD_ID field of some sort. It is easier to use that than to depend on such metadata&amp;nbsp;as the table name.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Aug 2018 02:27:37 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-08-16T02:27:37Z</dc:date>
    <item>
      <title>Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486932#M126779</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's common to have tables with different refreshed dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I have a group of tables which captures the active accounts on a weekly basis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The tables are stored in a specific folder. Let's say the folder is ACTIVE.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within this ACTIVE folder, I would have all the weekly refresh of the tables. Table naming convention (accounts_YYMMDD)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ACTIVE.accounts_180720&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ACTIVE.accounts_180727&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ACTIVE.accounts_180803&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ACTIVE.accounts_180810&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Some others, would have the refresh frequency on a monthly basis.&amp;nbsp;Table naming convention (AUM_YYMMDD)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ACTIVE.AUM_1801&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ACTIVE.AUM_1802&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ACTIVE.AUM_1803&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ACTIVE.AUM_1804&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The idea is, to automatically select the latest table from each group.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;From the two examples above, the latest tables should be ACTIVE.accounts_180810 and ACTIVE.AUM_1804.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there a more intelligent way to find out which one is the latest available table?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example, in an actual script, there's a proc sql&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select count(distinct fieldA) from ACTIVE.AUM_1801
;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;As of now, I need to manually changed it to whatever latest (ACTIVE.AUM_1804).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 09:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486932#M126779</guid>
      <dc:creator>t30</dc:creator>
      <dc:date>2018-08-15T09:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486934#M126780</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;Is there a more intelligent way" - yes there is, its not storing data like that.&amp;nbsp; Having one large master dataset with a column for date means simpler faster access to the data.&amp;nbsp; As it is now, your going to have to write code to identify the file you want - which means more coding resource, cpu time running etc. purely through bad data modelling.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc sort data=sashelp.vtable (obs=1);
  by descending memname;
  where libname="ACTIVE" and scan(memname,1,"_")="accounts";
run;
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;This takes all the memnames from the given libname, sorts them by name where prefixed with accounts, then the obs tells the output to only have one (which will be the lowest or highest depending on the sort - in this case biggest first).&amp;nbsp; Same thing for your other request, just change libname and scan.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 09:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486934#M126780</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-15T09:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486935#M126781</link>
      <description>&lt;P&gt;Unfortunately, the data is stored in that way, a legacy thing and I myself a mere user of the tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As of now, the tables are in that way to represent the snapshots at each date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example a table capturing the customers' account balances of a bank. The bank would want to know what's the snapshot of the account balance for all customers at month end, every month.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 10:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486935#M126781</guid>
      <dc:creator>t30</dc:creator>
      <dc:date>2018-08-15T10:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486940#M126784</link>
      <description>&lt;P&gt;Well, its your time.&amp;nbsp; Anyways did the sort work?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 10:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486940#M126784</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-15T10:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486961#M126796</link>
      <description>&lt;P&gt;PROC SQL is the way to go, but I would suggest putting the table names into macro variables. Fortunately, you just have to look for the maximum of the MEMNAME variable to get the latest table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select max(memname) into :accounts from dictionary.tables
  where libname='ACTIVE' and memname like 'ACCOUNTS%';
  select max(memname) into :aum from dictionary.tables
  where libname='ACTIVE' and memname like 'AUM%';
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can then refer to the macro variables with &amp;amp;ACCOUNTS and &amp;amp;AUM:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select Count(distinct FieldA) from Active.&amp;amp;aum;
quit;

proc summary data=active.&amp;amp;accounts nway missing;
  /* or whatever you want to do with your data */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Aug 2018 12:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/486961#M126796</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-08-15T12:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487016#M126819</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The idea is, to automatically select the latest table from each group.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;From the two examples above, the latest tables should be ACTIVE.accounts_180810 and ACTIVE.AUM_1804.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is there a more intelligent way to find out which one is the latest available table?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Define "latest". Do you mean that NAME of the file defines latest or the actual date that the dataset was updated or corrected?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A likely source in either case is to look at dictionary tables that SAS maintains for you. This will show what you can request from dictionary.tables.&lt;/P&gt;
&lt;PRE&gt;proc sql;
   describe table dictionary.tables;
quit;&lt;/PRE&gt;
&lt;P&gt;Notice that you can get MEMNAME (the table name) for a given LIBNAME (where clause), the Date Created, Date Modified if needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you select the MEMNAME and LIBNAME similar to the ones you want, parse the name for the date portion and select the latest date if using the table name OR the date created or modified if that is what you mean. In a perfect world they would be the same but we all know how that goes. Note that you can even check if the created and modified dates are the same if that is an issue.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 14:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487016#M126819</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-15T14:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487240#M126933</link>
      <description>Pretty much my employer's time and ressources ^^. The sort doesn't seem to produce any result though.&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Aug 2018 01:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487240#M126933</guid>
      <dc:creator>t30</dc:creator>
      <dc:date>2018-08-16T01:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487242#M126935</link>
      <description>&lt;P&gt;1. SAS will sort the data for you when you read all tables.&lt;/P&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ACCOUNTS_180720      
     ACCOUNTS_180727
     ACCOUNTS_180815
     ACCOUNTS_170811  ;
run;
data _null_;
  set ACCOUNTS_1: (obs=1) indsname=INDSNAME end=LASTOBS;
  if LASTOBS then call symput('lastest_period',scan(INDSNAME,2,'_'));
run;
%put &amp;amp;=lastest_period;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;LASTEST_PERIOD=180815&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;2. I disagree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;'s sweeping statement.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; Having one large master dataset with a column for date means simpler faster access to the data.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Large tables can be&amp;nbsp;extremely&amp;nbsp;slow to access, and the most recent data -which only represent a fraction of all the data- is the most often used. In this (very common) case, it makes a lot of sense to use the structure detailed here. When needed, accessing all the data sets in one go is a matter a creating a view.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. In any case, these tables&amp;nbsp;should&amp;nbsp;indeed&amp;nbsp;contain&amp;nbsp;a PERIOD_ID field of some sort. It is easier to use that than to depend on such metadata&amp;nbsp;as the table name.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 02:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487242#M126935</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-16T02:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487245#M126936</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&lt;/P&gt;&lt;P&gt;What do you intend to do with this data step?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ACCOUNTS_180720      
     ACCOUNTS_180727
     ACCOUNTS_180815
     ACCOUNTS_170811  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm not familiar with a data step without the set statement. Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 03:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487245#M126936</guid>
      <dc:creator>t30</dc:creator>
      <dc:date>2018-08-16T03:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487246#M126937</link>
      <description>As for the master dataset table, I'm sure there are pros and cons to each design.&lt;BR /&gt;&lt;BR /&gt;But I leave it to the data engineer equivalents to sort that out. ^^</description>
      <pubDate>Thu, 16 Aug 2018 03:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487246#M126937</guid>
      <dc:creator>t30</dc:creator>
      <dc:date>2018-08-16T03:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487247#M126938</link>
      <description>&lt;P&gt;This would do, the solution uses dictionary.tables, which I'm not aware of.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though I'm still working on it because it seems the code for the actual situation faces some other issues like&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; Data file XXXXX is in a format native to another host or the
      file encoding does not match the session encoding. Cross Environment Data Access will be used,
      which may require additional CPU resources and reduce performance.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 03:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487247#M126938</guid>
      <dc:creator>t30</dc:creator>
      <dc:date>2018-08-16T03:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487249#M126939</link>
      <description>&lt;P&gt;This is just to create the sample data.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 04:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487249#M126939</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-16T04:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Look for the latest table available</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487262#M126945</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&lt;/P&gt;&lt;P&gt;the max function, when applied to memname (which is a string), what's the behavior?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 05:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-for-the-latest-table-available/m-p/487262#M126945</guid>
      <dc:creator>t30</dc:creator>
      <dc:date>2018-08-16T05:18:11Z</dc:date>
    </item>
  </channel>
</rss>

