<?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 date from a file name in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743433#M38857</link>
    <description>I want that column in the dataset. We have to add the column in the dataset containing the files.&lt;BR /&gt;I might not be able to provide you the exact code right now but i can give you a brief how I am doing it,&lt;BR /&gt;I am pulling all the files names first from the files and then stored them in a macro and then used that macro in proc import to pull the files using call execute macro.&lt;BR /&gt;&lt;BR /&gt;Hope that helps</description>
    <pubDate>Mon, 24 May 2021 20:44:12 GMT</pubDate>
    <dc:creator>Nimish28</dc:creator>
    <dc:date>2021-05-24T20:44:12Z</dc:date>
    <item>
      <title>How to extract date from a file name</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743423#M38855</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;I have multiple xlsx files (for example abc_20200101.xlsx ) , i have 38 files like this and i want to extract the dates from these file names into a new column.&lt;BR /&gt;I am already reading the files using macros but unable to find a logic that will fit in.&lt;BR /&gt;It would be really great if any could help me here.&lt;BR /&gt;&lt;BR /&gt;Thank you in advance!</description>
      <pubDate>Mon, 24 May 2021 19:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743423#M38855</guid>
      <dc:creator>Nimish28</dc:creator>
      <dc:date>2021-05-24T19:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract date from a file name</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743425#M38856</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/336790"&gt;@Nimish28&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi All,&lt;BR /&gt;&lt;BR /&gt;I have multiple xlsx files (for example abc_20200101.xlsx ) , i have 38 files like this and i want to extract the dates from these file names into a new column.&lt;BR /&gt;I am already reading the files using macros but unable to find a logic that will fit in.&lt;BR /&gt;It would be really great if any could help me here.&lt;BR /&gt;&lt;BR /&gt;Thank you in advance!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show us the code you are using to read the files. That may contain enough information we can help.&lt;/P&gt;
&lt;P&gt;You also need to tell us where you expect to store that "date". In the data set created when reading the file, in a different data set, in a macro variable, in a document (and what type) or someplace else.&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 19:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743425#M38856</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-24T19:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract date from a file name</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743433#M38857</link>
      <description>I want that column in the dataset. We have to add the column in the dataset containing the files.&lt;BR /&gt;I might not be able to provide you the exact code right now but i can give you a brief how I am doing it,&lt;BR /&gt;I am pulling all the files names first from the files and then stored them in a macro and then used that macro in proc import to pull the files using call execute macro.&lt;BR /&gt;&lt;BR /&gt;Hope that helps</description>
      <pubDate>Mon, 24 May 2021 20:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743433#M38857</guid>
      <dc:creator>Nimish28</dc:creator>
      <dc:date>2021-05-24T20:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract date from a file name</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743435#M38858</link>
      <description>&lt;P&gt;Since you are using Proc import you will have to parse the bit of data you want out of the file name and then use a data step to bring that parsed value into the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;%let mvar=folder\subfolder\abc_20200101.xlsx ;

data _null_;
   date = input(substr("&amp;amp;mvar.",index("&amp;amp;mvar.",".")-8,8),yymmdd10.);
   call sumputx('mdate',date);
run;

data want;
   set yourdatasetname;
   date = &amp;amp;mdate;
   format date yymmdd10.;
run;&lt;/PRE&gt;
&lt;P&gt;Assumes that you have a variable that holds a single name of the file.&lt;/P&gt;
&lt;P&gt;The data null step searches that "name" for the period before xlsx and pulls in the 8 characters of the date and uses an appropriate informat to read that text into a date value, creates another macro variable to use in a data step to add the variable to your data set. This assumes the "yourdataset" has been made, such as proc import import.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caution since you are using Proc Import: &lt;STRONG&gt;You&lt;/STRONG&gt; have to pick a name for the date variable that &lt;STRONG&gt;never&lt;/STRONG&gt; appears in the columns of&amp;nbsp;&lt;STRONG&gt;any&lt;/STRONG&gt; the XLSX files. As it hasn't yet and never will appear in the future with any of the files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caution: If your file names ever have more than one period or use fewer or more digits for the date, or appear in any other order than YYYYMMDD the above code will not work and you will have to go back to the drawing board.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 21:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743435#M38858</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-24T21:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract date from a file name</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743533#M38859</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path= c:\temp ;

data want;
 rc=filename('x',"&amp;amp;path");
 did=dopen('x');
 do i=1 to dnum(did);
   fname=dread(did,i);
   if prxmatch('/\d{8}\.xlsx/',fname) then do;
    want=scan(fname,-1,,'kd');output;
   end;
 end;
drop rc did i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 May 2021 12:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-extract-date-from-a-file-name/m-p/743533#M38859</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-25T12:32:14Z</dc:date>
    </item>
  </channel>
</rss>

