<?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: Excel file import with year and value check and fix within the file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747032#M234432</link>
    <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519" target="_blank" rel="noopener"&gt;Emma2021&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After you import your Excel file into SAS table, you can clean up your DATE variable. Let's say, you imported your Excel file into SAS dataset HAVE. Then you can do the following manipulation to reconstruct your DATE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
   set HAVE; 

   /* get day and month */
   D = day(DATE);
   M = month(DATE);
&lt;BR /&gt;   /* reconstruct your DATE */
   DATE = mdy(M,D,2020);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0bo5thbfrcab1n1menkqxq2suiv.htm" target="_self"&gt;MDY() function&lt;/A&gt; calculates SAS date value out of Month, Day and Year.&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Jun 2021 14:11:47 GMT</pubDate>
    <dc:creator>LeonidBatkhan</dc:creator>
    <dc:date>2021-06-10T14:11:47Z</dc:date>
    <item>
      <title>Excel file import with year and value check and fix within the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747007#M234425</link>
      <description>&lt;P&gt;I have excel file (attached). It has file name (Test 2020 file) and date variable with actual date such as 1/1/2020 etc.. Some year are incorrect (2045 and 1999), but all should be 2020 not 1999 or 2045. How can I check and fix accordingly? Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 12:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747007#M234425</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2021-06-10T12:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Excel file import with year and value check and fix within the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747032#M234432</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519" target="_blank" rel="noopener"&gt;Emma2021&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After you import your Excel file into SAS table, you can clean up your DATE variable. Let's say, you imported your Excel file into SAS dataset HAVE. Then you can do the following manipulation to reconstruct your DATE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
   set HAVE; 

   /* get day and month */
   D = day(DATE);
   M = month(DATE);
&lt;BR /&gt;   /* reconstruct your DATE */
   DATE = mdy(M,D,2020);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0bo5thbfrcab1n1menkqxq2suiv.htm" target="_self"&gt;MDY() function&lt;/A&gt; calculates SAS date value out of Month, Day and Year.&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 14:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747032#M234432</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2021-06-10T14:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Excel file import with year and value check and fix within the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747228#M234494</link>
      <description>Instead of 2020 that hard code, there is a way to capture dynamically from the file name? Since there are 100 files--it would be hard to manually write like this.&lt;BR /&gt;For example files names are as the following:&lt;BR /&gt;Test 2000 Q1 file&lt;BR /&gt;Test another 2000 Q2&lt;BR /&gt;Test vk 2001 Q1 etc</description>
      <pubDate>Thu, 10 Jun 2021 22:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747228#M234494</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2021-06-10T22:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Excel file import with year and value check and fix within the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747232#M234496</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;, how are you importing the files?&amp;nbsp; Do you have a macro that searches a particular directory and processes all files of a certain type?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At some point in the processing, the file name must be known or you won't be able to process it.&amp;nbsp; If we can capture the file name, we can extract the year and then add it to the MDY function mentioned in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51532"&gt;@LeonidBatkhan&lt;/a&gt;'s reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 22:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747232#M234496</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-10T22:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Excel file import with year and value check and fix within the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747238#M234499</link>
      <description>&lt;P&gt;You of course have to first be able to determine the filename inside a Data step, but once you've determined the filename, a parsing routine like the one below can extract the year from the filename.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	WORK.Years_Only;
	DROP	_:;
	LENGTH	_File_Name	$256;

	INFILE	DATALINES	MISSOVER;

	INPUT	_File_Name	$;
	
	_No_More_Characters							=	0;
	_Start_Pos									=	1;

	DO	UNTIL	(_No_More_Characters);
		_Start_Pos								=	ANYDIGIT(_File_Name, _Start_Pos);
		_End_Pos								=	_Start_Pos	+	3;

		IF	_Start_Pos							=	0					OR
			_Start_Pos							&amp;gt;	LENGTH(_File_Name)	OR
			_End_Pos							&amp;gt;	LENGTH(_File_Name)	THEN
			_No_More_Characters					=	1;
		ELSE
			IF	NOTDIGIT(SUBSTR(_File_Name, _Start_Pos, 4))	THEN
				DO;
					_Start_PoS					=	_Start_Pos	+	1;
					IF	_Start_Pos				&amp;gt;	LENGTH(_File_Name)	THEN
						_No_More_Characters		=	1;
				END;
			ELSE
				DO;
					Year						=	SUBSTR(_File_Name, _Start_Pos, 4);
					_No_More_Characters			=	1;
				END;
	END;

DATALINES;
Test_2000_Q1_file
Test_another_2000_Q2
Test_vk_2001_Q1
Test1_2002
Test26_2003_50
Test75_80_2004
No_Year_Here
2005_is_the_year
Howabout2006forayear
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 23:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-file-import-with-year-and-value-check-and-fix-within-the/m-p/747238#M234499</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-10T23:40:09Z</dc:date>
    </item>
  </channel>
</rss>

