<?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: Find a table in a library based on specific parameters in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81099#M23391</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Untested&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql noprint;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select max(substr(memname,1,9)) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;into :lastMember&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from dictionary.tables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;where libname="FTM";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%put &amp;amp;lastMember;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The table name that you want should be in macro variable lastMember.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Jul 2013 17:12:13 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2013-07-16T17:12:13Z</dc:date>
    <item>
      <title>Find a table in a library based on specific parameters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81098#M23390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a library named FTM. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The tables in this library goes like this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FTM201102&lt;/P&gt;&lt;P&gt;FTM201304&lt;/P&gt;&lt;P&gt;FTM201305T&lt;/P&gt;&lt;P&gt;FTM201306&lt;/P&gt;&lt;P&gt;FTM201306T&lt;/P&gt;&lt;P&gt;FTM201307&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to have a sas or sql query that looks in that library and find the latest table based on those parameters :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The six digits after FTM are always : YYYYMM&lt;/P&gt;&lt;P&gt;The table name can either finish with a T or not&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to write my query so that it could return the latest table ending with or without a T and put the result in a variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please help me write that query?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and time&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 15:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81098#M23390</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-07-16T15:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Find a table in a library based on specific parameters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81099#M23391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Untested&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql noprint;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select max(substr(memname,1,9)) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;into :lastMember&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from dictionary.tables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;where libname="FTM";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%put &amp;amp;lastMember;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The table name that you want should be in macro variable lastMember.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 17:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81099#M23391</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-07-16T17:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find a table in a library based on specific parameters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81100#M23392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for the quick reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;max(substr(memname,1,9)) only returns the last table based on alphabetical order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within my library, I have a table named tmp_ftm2010 and it returned tmp_ftm20.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I think we are getting closer to the solution with the use of dictionary.tables where libname = "FTM".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would it be possible to do something like (VBA like) in SAS or SQL :&lt;/P&gt;&lt;P&gt;mydate = 0&lt;/P&gt;&lt;P&gt;For each tables in&amp;nbsp; libname="FTM"&lt;/P&gt;&lt;P&gt;if substr(memname,1,3) = "FTM" &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;then &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;if right(memname,1) = "T" then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if substr(memname,4,6) &amp;gt; mydate then mydate = substr(memname,4,6)&lt;/P&gt;&lt;P&gt;end if &lt;/P&gt;&lt;P&gt;end if&lt;/P&gt;&lt;P&gt;Next tables&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;mytablename = "FTM" &amp;amp; mydate &amp;amp; "T"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope you understand what I am trying to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and time&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 19:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81100#M23392</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-07-16T19:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Find a table in a library based on specific parameters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81101#M23393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you try adding to &lt;A __default_attr="2746" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt; where condition:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and memname=: "FTM"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which should limit to only tables that start with FTM. Of course if their are tables with and without a T with the same date I think it would only return the without T version.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EJ&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 19:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81101#M23393</guid>
      <dc:creator>esjackso</dc:creator>
      <dc:date>2013-07-16T19:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find a table in a library based on specific parameters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81102#M23394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The code doesn't work, because you didn't provide all the information. Add a filter to the sql step to only get tables that start with FTM first, then try it again. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This method is faster than what you're suggesting. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 19:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81102#M23394</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-07-16T19:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Find a table in a library based on specific parameters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81103#M23395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, the SUBSTR part is not necessary, this should do the trick :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql noprint;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select max(memname) &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;into :lastMember&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from dictionary.tables&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;where libname="FTM" and memname like "FTM%";&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%put &amp;amp;lastMember;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could also use pattern matching, but that might be overkill.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 19:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81103#M23395</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-07-16T19:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Find a table in a library based on specific parameters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81104#M23396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For my specific need, this works like a charm :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select max(memname) &lt;/P&gt;&lt;P&gt;into :lastMember&lt;/P&gt;&lt;P&gt;from dictionary.tables&lt;/P&gt;&lt;P&gt;where libname="FTM" and memname like "FTM201%" and substr(memname,length(memname)-1,1) = "T";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;lastMember;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 22:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-a-table-in-a-library-based-on-specific-parameters/m-p/81104#M23396</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-07-16T22:33:08Z</dc:date>
    </item>
  </channel>
</rss>

