<?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: Fetch file from libname regardless of date extension in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676846#M204105</link>
    <description>Use SASHELP.VTABLE to find the latest data set. You can use either the created or modified date or you can parse the date from the file name. &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 14 Aug 2020 19:26:35 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-08-14T19:26:35Z</dc:date>
    <item>
      <title>Fetch file from libname regardless of date extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676844#M204104</link>
      <description>&lt;P&gt;&lt;BR /&gt;DATA _NULL_;&lt;BR /&gt;call symput( "Today", COMPRESS(left( put( date(),YYMMDDn8.) ) )) ;/*today for report date exten*/&lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;%PUT &amp;amp;Today;&lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table new1 as&lt;BR /&gt;select make,model,invoice&lt;BR /&gt;from sashelp.cars&lt;BR /&gt;where invoice &amp;lt;=20000&lt;BR /&gt;;quit;&lt;/P&gt;
&lt;P&gt;/*bring in car_id from libname*/&lt;BR /&gt;proc sql;&lt;BR /&gt;create table cars2 as&lt;BR /&gt;select a.make,a.model,a.invoice,b.car_id&lt;BR /&gt;from new1 a&lt;BR /&gt;inner join gs1.inventory_&amp;amp;Today.&lt;BR /&gt;;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is that I need to fetch and use a file called inventory from the gs library.&amp;nbsp; Even though I am showing a macro (&amp;amp;today) to capture the date,&amp;nbsp; the actual date in the libname is not consistent each month.&amp;nbsp; (ie last month the file name was inventory_20200805,&amp;nbsp; two months ago&amp;nbsp; inventory_20200702)&lt;/P&gt;
&lt;P&gt;Is there a way to develop or imporve the existing date macro to capture the exact file regardless of the date extension each month.&amp;nbsp; This will enable me to automate the run of the report each month&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 19:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676844#M204104</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-08-14T19:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch file from libname regardless of date extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676846#M204105</link>
      <description>Use SASHELP.VTABLE to find the latest data set. You can use either the created or modified date or you can parse the date from the file name. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Aug 2020 19:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676846#M204105</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-14T19:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch file from libname regardless of date extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676914#M204128</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table inven as
select memname, input(scan(memname,-1,'_'),yymmdd8n.) as date from sashelp.vtable where 
strip(upcase(libname)) = 'GS1'
and index(strip(upcase(memname)),'INVENTORY_')&amp;gt;0
order by date desc;
quit;

data _null_;
set inven;
if _n_ =1 then call symputx('dsname',memname);
run;
* Your code here on using the dataset dsname;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 Aug 2020 01:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676914#M204128</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-08-15T01:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch file from libname regardless of date extension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676920#M204132</link>
      <description>&lt;P&gt;SQL will process character data within summary functions such as max/min. Because the date is in the format YYMMDD it will sort correctly so you can just pick the maximum data set name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select memname into : mydataset
from sashelp.vtable
where libname = upcase('WORK') and upcase(memname) like 'CLASS%'
having max(memname) = memname;
quit;

%put &amp;amp;mydataset;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Full code to test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class_20200813;
set sashelp.class;
run;

data class_20200812;
set sashelp.class;
run;

data class_20200811;
set sashelp.class;
run;

data class_20200810;
set sashelp.class;
run;

data class_20200809;
set sashelp.class;
run;

data class_20200808;
set sashelp.class;
run;


proc sql;
select memname into : mydataset
from sashelp.vtable
where libname = upcase('WORK') and upcase(memname) like 'CLASS%'
having max(memname) = memname;
quit;

%put &amp;amp;mydataset;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214340"&gt;@smantha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table inven as
select memname, input(scan(memname,-1,'_'),yymmdd8n.) as date from sashelp.vtable where 
strip(upcase(libname)) = 'GS1'
and index(strip(upcase(memname)),'INVENTORY_')&amp;gt;0
order by date desc;
quit;

data _null_;
set inven;
if _n_ =1 then call symputx('dsname',memname);
run;
* Your code here on using the dataset dsname;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Aug 2020 02:20:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetch-file-from-libname-regardless-of-date-extension/m-p/676920#M204132</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-15T02:20:51Z</dc:date>
    </item>
  </channel>
</rss>

