<?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 extract latest dataset in a library and macro in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301963#M60663</link>
    <description>&lt;P&gt;How do you know which data set is the latest? Is there some naming convention like a date in the name or a sequence number?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so then you don't need to write a macro but you query the dictionary.tables and populate a macro variable for later use (see sample code below).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
  select cats(libname,'.',memname) into :my_table_name
  from dictionary.tables
  where libname='COMMON' and memname ....&amp;lt;some condition(s) selecting the required table&amp;gt;
  ;
quit;


data want;
  set &amp;amp;my_table_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Oct 2016 05:27:33 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2016-10-03T05:27:33Z</dc:date>
    <item>
      <title>How to extract latest dataset in a library and macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301962#M60662</link>
      <description>Just I wanted to extract latest dataset in a library called common. I tried to use proc sql but it's display all the datasets, I need single dataset which id created recently and later I need to write macro for the same.&lt;BR /&gt;&lt;BR /&gt;Any idea how to do it?</description>
      <pubDate>Mon, 03 Oct 2016 05:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301962#M60662</guid>
      <dc:creator>Ravikumarpa4</dc:creator>
      <dc:date>2016-10-03T05:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract latest dataset in a library and macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301963#M60663</link>
      <description>&lt;P&gt;How do you know which data set is the latest? Is there some naming convention like a date in the name or a sequence number?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so then you don't need to write a macro but you query the dictionary.tables and populate a macro variable for later use (see sample code below).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
  select cats(libname,'.',memname) into :my_table_name
  from dictionary.tables
  where libname='COMMON' and memname ....&amp;lt;some condition(s) selecting the required table&amp;gt;
  ;
quit;


data want;
  set &amp;amp;my_table_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Oct 2016 05:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301963#M60663</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-03T05:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract latest dataset in a library and macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301965#M60664</link>
      <description>&lt;P&gt;How is this different than your previous question which had several worked examples?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300732#M60544" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300732#M60544&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you absolutely want a macro because it's your homework wrap the code between %macro and %mend.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro latest_date();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*code already provided;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%latest_date;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want some sort of dynamic nature to this you need to be more explicit in your requirements. You could add parameters for library name and what you wanted the macro variable to be called. But you haven't explained what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a link on into to macro programming to help you change the code if required.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 06:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301965#M60664</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-03T06:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract latest dataset in a library and macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301977#M60665</link>
      <description>&lt;P&gt;As mentioned&amp;nbsp;by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick﻿&lt;/a&gt;, DICTIONARY.TABLES should contain the information you need. I suspect that&amp;nbsp;you could use the CRDATE and MODATE columns. To get the latest, use the max() function with a HAVING statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 08:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301977#M60665</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-03T08:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract latest dataset in a library and macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301982#M60666</link>
      <description>Hi&lt;BR /&gt;I used create and desc order but it displays all the records created by&lt;BR /&gt;date but now I want only top line record in macro.&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Mon, 03 Oct 2016 08:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301982#M60666</guid>
      <dc:creator>Ravikumarpa4</dc:creator>
      <dc:date>2016-10-03T08:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract latest dataset in a library and macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301985#M60667</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/104494"&gt;@Ravikumarpa4&lt;/a&gt; wrote:&lt;BR /&gt;Just I wanted to extract latest dataset in a library called common. I tried to use proc sql but it's display all the datasets, I need single dataset which id created recently and later I need to write macro for the same.&lt;BR /&gt;&lt;BR /&gt;Any idea how to do it?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;See this example:&lt;/P&gt;
&lt;PRE&gt;16         proc sql noprint;
17         select name into :names from sashelp.class order by name descending;
18         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

19         %put "names=&amp;amp;names";
"names=William "
&lt;/PRE&gt;
&lt;P&gt;Note that the macro variable contains only &lt;U&gt;one&lt;/U&gt; entry, coming from the first line that the &lt;FONT face="courier new,courier"&gt;order by&lt;/FONT&gt; clause delivers.&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select memname into :memname from dictionary.tables
where libname = 'COMMON'
order by memname descending;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should deliver the last dataset from library &lt;FONT face="courier new,courier"&gt;COMMON&lt;/FONT&gt; in macro variable &lt;FONT face="courier new,courier"&gt;&amp;amp;memname&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 09:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-latest-dataset-in-a-library-and-macro/m-p/301985#M60667</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-03T09:09:00Z</dc:date>
    </item>
  </channel>
</rss>

