<?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 Extracting Year Month date from excel file name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-Month-date-from-excel-file-name/m-p/305132#M65057</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have file names with "Sample&amp;nbsp;Response&amp;nbsp;&lt;STRONG&gt;August 2 2016&lt;/STRONG&gt;.xlsx", please let me know how to extract the month year date from file name and update in a variable instead of a hardcoded value like mentioned in below sas program.i.e. &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Received_dt variable&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename fnames pipe 'ls /user/path/*.xlsx"';


data fnames;
    infile fnames pad missover;
    input @1 filename $255.;
    n=_n_;
run;


proc sql noprint; select count(filename) into :num from fnames; quit;

%macro file_process;
    %do i=1 %to &amp;amp;num;

        proc sql noprint;
            select strip(filename) into :filename from fnames where n=&amp;amp;i;
        quit;

	%let file_proc = &amp;amp;filename;
	libname XLSFILE XLSX "&amp;amp;file_proc";
	options validvarname=v7;
	options SYMBOLGEN MPRINT;

	PROC SQL;
    	create table  work.data_raw as 
	(select * from XLSFILE.SHEET1);
	quit;

	data work.data(rename=(number=number_1));
	set work.data_raw;
	format Received_dt mmddyy10.;
	&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Received_dt = "02AUG2016"d;&lt;/FONT&gt;&lt;/STRONG&gt;
	run;

	PROC SQL;
    	create table  work.data_raw_2 as 
	(select * from xlsFile.'SHEET2$A3:L2000'n);
	quit;

	data work.data2;
	set work.data_raw_2;
	format Load_dt mmddyy10.;
	format Received_dt mmddyy10.;
	&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Received_dt = "02AUG2016"d;&lt;/FONT&gt;&lt;/STRONG&gt;
	run;

    %end;
%mend;

	%file_process;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2016 16:04:27 GMT</pubDate>
    <dc:creator>jayakumarmm</dc:creator>
    <dc:date>2016-10-17T16:04:27Z</dc:date>
    <item>
      <title>Extracting Year Month date from excel file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-Month-date-from-excel-file-name/m-p/305132#M65057</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have file names with "Sample&amp;nbsp;Response&amp;nbsp;&lt;STRONG&gt;August 2 2016&lt;/STRONG&gt;.xlsx", please let me know how to extract the month year date from file name and update in a variable instead of a hardcoded value like mentioned in below sas program.i.e. &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Received_dt variable&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename fnames pipe 'ls /user/path/*.xlsx"';


data fnames;
    infile fnames pad missover;
    input @1 filename $255.;
    n=_n_;
run;


proc sql noprint; select count(filename) into :num from fnames; quit;

%macro file_process;
    %do i=1 %to &amp;amp;num;

        proc sql noprint;
            select strip(filename) into :filename from fnames where n=&amp;amp;i;
        quit;

	%let file_proc = &amp;amp;filename;
	libname XLSFILE XLSX "&amp;amp;file_proc";
	options validvarname=v7;
	options SYMBOLGEN MPRINT;

	PROC SQL;
    	create table  work.data_raw as 
	(select * from XLSFILE.SHEET1);
	quit;

	data work.data(rename=(number=number_1));
	set work.data_raw;
	format Received_dt mmddyy10.;
	&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Received_dt = "02AUG2016"d;&lt;/FONT&gt;&lt;/STRONG&gt;
	run;

	PROC SQL;
    	create table  work.data_raw_2 as 
	(select * from xlsFile.'SHEET2$A3:L2000'n);
	quit;

	data work.data2;
	set work.data_raw_2;
	format Load_dt mmddyy10.;
	format Received_dt mmddyy10.;
	&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Received_dt = "02AUG2016"d;&lt;/FONT&gt;&lt;/STRONG&gt;
	run;

    %end;
%mend;

	%file_process;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 16:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-Month-date-from-excel-file-name/m-p/305132#M65057</guid>
      <dc:creator>jayakumarmm</dc:creator>
      <dc:date>2016-10-17T16:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Year Month date from excel file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-Month-date-from-excel-file-name/m-p/305137#M65058</link>
      <description>&lt;P&gt;The easiest place to do this would be in your initial DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input @1 filename $255.;&lt;/P&gt;
&lt;P&gt;length mon $ 3&amp;nbsp; year $ 4&amp;nbsp; day $ 2;&lt;/P&gt;
&lt;P&gt;year = scan(filename, -1);&lt;/P&gt;
&lt;P&gt;day = scan(filename, -2);&lt;/P&gt;
&lt;P&gt;mon = scan(filename, -3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point, all the pieces are character, so it is possible you may need to convert some of them later ... depending on what you are trying to achieve with them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the LENGTH statement defines MON as $ 3, so you already have the three-character abbreviation there (suitable for a date literal such as 02Aug2016).&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 16:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-Month-date-from-excel-file-name/m-p/305137#M65058</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-17T16:21:02Z</dc:date>
    </item>
  </channel>
</rss>

