<?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 get the latest dataset from a library in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944493#M370053</link>
    <description>&lt;P&gt;this one worked fine&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kajal&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2024 18:59:07 GMT</pubDate>
    <dc:creator>kajal_30</dc:creator>
    <dc:date>2024-09-18T18:59:07Z</dc:date>
    <item>
      <title>How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944474#M370042</link>
      <description>&lt;P&gt;I have lots of datasets in a SAS library but I want to choose the latest one&amp;nbsp;&lt;/P&gt;&lt;P&gt;for eg library has&lt;/P&gt;&lt;P&gt;abc_2401&lt;/P&gt;&lt;P&gt;abc_2402&lt;/P&gt;&lt;P&gt;abc_2407&lt;/P&gt;&lt;P&gt;abc_2408&lt;/P&gt;&lt;P&gt;efg_2402&lt;/P&gt;&lt;P&gt;efg_2401&lt;/P&gt;&lt;P&gt;hij_2401&lt;/P&gt;&lt;P&gt;hij_2402&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;how to extract the dataset abc_2408 from the whole list of datasets.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Kajal&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 17:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944474#M370042</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-09-18T17:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944475#M370043</link>
      <description>&lt;P&gt;It depends on what you mean by 'latest'? Please be specific.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 17:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944475#M370043</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2024-09-18T17:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944476#M370044</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I said in the last line need&amp;nbsp;&lt;STRONG&gt;abc_2408&amp;nbsp;&lt;/STRONG&gt;which is the latest dataset having prefix abc&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 17:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944476#M370044</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-09-18T17:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944478#M370046</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select name into :latest from dictionary.tables where libname='YOURLIBNAME' 
    having scan(memname,2,'_')=max(scan(memname,2,'_'));
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This creates a macro variable named &amp;amp;LATEST with the value abc_2408.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: Latest is a meaningless word here without additional information. If you have said the value after the underscore is a date in the format YYMM and you want the latest date, that would be a lot more clear. Spending a little extra time (perhaps one minute in this case) to make sure your meaning is clear is always a good thing to do.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 17:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944478#M370046</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-18T17:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944480#M370047</link>
      <description>&lt;P&gt;the code provided didn't work for me getting below in logs:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: The query requires remerging summary statistics back with the original data.&lt;BR /&gt;NOTE: No rows were selected.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 17:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944480#M370047</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-09-18T17:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944481#M370048</link>
      <description>&lt;P&gt;Make sure to use the correct variable (MEMNAME in the this case) into the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select memname into :latest trimmed
  from dictionary.tables
  where libname='EG' 
    and memname like 'ABC^_' escape '^'
  having scan(memname,-1,'_')=max(scan(memname,-1,'_'))
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that LIBNAME (and MEMNAME) variable in DICTIONARY.TABLES is always in uppercase.&amp;nbsp; So assuming the string EG in your original post is the name of the libref that you want find the dataset in then the code should look like above to find the latest ABC_yymm dataset.&amp;nbsp; If the libref is something else then modify the code to reflect the name that was used for the library.&amp;nbsp; &amp;nbsp;If you want to find the latest version of some other dataset then change the value used in the WHERE clause.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 18:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944481#M370048</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-18T18:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944483#M370050</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;the code provided didn't work for me getting below in logs:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: The query requires remerging summary statistics back with the original data.&lt;BR /&gt;NOTE: No rows were selected.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;IMPORTANT RULE: show us your code — don't just say it didn't work. Right now, we don't know what you did, so we can't tell you how to fix it.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 18:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944483#M370050</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-18T18:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944493#M370053</link>
      <description>&lt;P&gt;this one worked fine&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kajal&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 18:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944493#M370053</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-09-18T18:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the latest dataset from a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944494#M370054</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I said in the last line need&amp;nbsp;&lt;STRONG&gt;abc_2408&amp;nbsp;&lt;/STRONG&gt;which is the latest dataset having prefix abc&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is an example, not a rule.&lt;/P&gt;
&lt;P&gt;Computer programs need rules to apply in more generic cases.&lt;/P&gt;
&lt;P&gt;For example, how do I know you wanted "abc_2408" if there was a "pdq_2408"?&lt;/P&gt;
&lt;P&gt;I think you need at least 2 rules, one involving the part before the _ (if any) and if 2408 is supposed to contain some sort of date information tell us how to parse it to determine "latest".&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 19:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-latest-dataset-from-a-library/m-p/944494#M370054</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-09-18T19:01:48Z</dc:date>
    </item>
  </channel>
</rss>

