<?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: Pull in the last modified file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745965#M233937</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89165"&gt;@Krysia24&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I receive two errors: 1.) Insufficient authorization to access PIPE.; 2.) Error in the filename statement.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This means that option NOXCMD is set, and you can't use the interfaces to the system (FILENAME PIPE, X, %SYSEXEC, SYSTEM function, CALL SYSTEM).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all your files are SAS dataset files, define a library for the directory, and pull the timestamps from DICTIONARY.TABLES.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have other types of files, use the file functions:&lt;/P&gt;
&lt;P&gt;FILENAME to assign a file reference to the directory&lt;/P&gt;
&lt;P&gt;DOPEN to open the directory&lt;/P&gt;
&lt;P&gt;in a DO loop from 1 to DNUM, use DREAD, FILENAME and FOPEN (or MOPEN) for the individual file and FINFO to retrieve the modification timestamp.&lt;/P&gt;
&lt;P&gt;You can find examples for similar code here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Modify-file-deletion-code-to-only-delete-files-older-than-5-days/m-p/636601#M189139" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Modify-file-deletion-code-to-only-delete-files-older-than-5-days/m-p/636601#M189139&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 05 Jun 2021 06:53:33 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-06-05T06:53:33Z</dc:date>
    <item>
      <title>Pull in the last modified file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745906#M233917</link>
      <description>&lt;P&gt;Trying to figure out how to pull in the last outputted/last modified file. Let's say I have a file&amp;nbsp; called "spreadsheet.sas7bdat" in this library: "C:\" and I want to pull the last outputted "spreadsheet" file into SAS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am operating in a Windows environment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had stumbled upon this sample code but have not been successful in adapting it:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro lastmodifiedfile(path,MName);&lt;BR /&gt;&lt;BR /&gt;filename test pipe "dir &amp;amp;path /od /t:w /b";&amp;nbsp;&lt;BR /&gt;data _null_;&lt;BR /&gt;infile test;&lt;BR /&gt;input;&lt;BR /&gt;call symputx("&amp;amp;Mname.",_infile_,'g');&lt;BR /&gt;run;&lt;BR /&gt;%put Last file to be modified in &amp;amp;path is: &amp;amp;Mname.;&lt;BR /&gt;&lt;BR /&gt;%mend lastmodifiedfile;&lt;BR /&gt;%lastmodifiedfile(/dwh_operation/sasdata/smp_production/prod_smpi2/pilot/,Fname);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 20:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745906#M233917</guid>
      <dc:creator>Krysia24</dc:creator>
      <dc:date>2021-06-04T20:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Pull in the last modified file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745907#M233918</link>
      <description>What happens when you run the following:&lt;BR /&gt;&lt;BR /&gt;%macro lastmodifiedfile(path,MName);&lt;BR /&gt;&lt;BR /&gt;filename test pipe "dir &amp;amp;path /od /t:w /b"; &lt;BR /&gt;data _null_;&lt;BR /&gt;infile test;&lt;BR /&gt;input;&lt;BR /&gt;call symputx("&amp;amp;Mname.",_infile_,'g');&lt;BR /&gt;run;&lt;BR /&gt;%put Last file to be modified in &amp;amp;path is: &amp;amp;Mname.;&lt;BR /&gt;&lt;BR /&gt;%mend lastmodifiedfile;&lt;BR /&gt;%lastmodifiedfile(/dwh_operation/sasdata/smp_production/prod_smpi2/pilot/,Fname);&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;fname.;</description>
      <pubDate>Fri, 04 Jun 2021 20:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745907#M233918</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-04T20:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Pull in the last modified file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745916#M233922</link>
      <description>&lt;P&gt;Are you trying find out about a SAS dataset in a library or an external file? Not seeing an actual immediate connection between a SAS data set and "last outputted".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to know about SAS data sets what you have is not the way to go about it if you have a library defined.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 20:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745916#M233922</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-04T20:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: Pull in the last modified file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745917#M233923</link>
      <description>&lt;P&gt;I receive two errors: 1.) Insufficient authorization to access PIPE.; 2.) Error in the filename statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 20:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745917#M233923</guid>
      <dc:creator>Krysia24</dc:creator>
      <dc:date>2021-06-04T20:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Pull in the last modified file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745926#M233925</link>
      <description>&lt;P&gt;Assuming you have a library named demo, something like this should work. It creates a macro variable, last_modified_data that contains the name of the last modified data set you can use in your programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;demo&lt;/STRONG&gt; &lt;/FONT&gt;'C:\';

proc sql noprint;
select memname into :&lt;FONT color="#800080"&gt;&lt;STRONG&gt;last_modified_data&lt;/STRONG&gt; &lt;/FONT&gt;from sashelp.vtable where libname = upper("&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;demo&lt;/STRONG&gt;&lt;/FONT&gt;")  having modate = max(modate);
quit;

%put &amp;amp;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;last_modified_data&lt;/FONT&gt;&lt;/STRONG&gt;.&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89165"&gt;@Krysia24&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Trying to figure out how to pull in the last outputted/last modified file. Let's say I have a file&amp;nbsp; called "spreadsheet.sas7bdat" in this library: "C:\" and I want to pull the last outputted "spreadsheet" file into SAS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am operating in a Windows environment.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had stumbled upon this sample code but have not been successful in adapting it:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro lastmodifiedfile(path,MName);&lt;BR /&gt;&lt;BR /&gt;filename test pipe "dir &amp;amp;path /od /t:w /b";&amp;nbsp;&lt;BR /&gt;data _null_;&lt;BR /&gt;infile test;&lt;BR /&gt;input;&lt;BR /&gt;call symputx("&amp;amp;Mname.",_infile_,'g');&lt;BR /&gt;run;&lt;BR /&gt;%put Last file to be modified in &amp;amp;path is: &amp;amp;Mname.;&lt;BR /&gt;&lt;BR /&gt;%mend lastmodifiedfile;&lt;BR /&gt;%lastmodifiedfile(/dwh_operation/sasdata/smp_production/prod_smpi2/pilot/,Fname);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 21:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745926#M233925</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-04T21:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Pull in the last modified file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745959#M233932</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89165"&gt;@Krysia24&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I receive two errors: 1.) Insufficient authorization to access PIPE.; 2.) Error in the filename statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;OK, that's a problem ("Insufficient authorization to access PIPE").&amp;nbsp; That means that your installation/company has turned off the ability for you to use the PIPE command as part of a file name.&amp;nbsp; The "Error in the filename statement" is caused by the inability to use the PIPE command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried using an "X" command?&amp;nbsp; You could use an "X" in lieu of a Filename with the PIPE command.&amp;nbsp; The "X" command can be used to run the Dir command which can be saved as a .txt file, and then you can read the .txt file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 04:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745959#M233932</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-05T04:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Pull in the last modified file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745960#M233933</link>
      <description>&lt;P&gt;Below is a working example using the X command.&amp;nbsp; I added *.xlsx and *.xls since it sounds like you just want spreadsheets.&amp;nbsp; I hope this will be helpful, but if the PIPE command is blocked, the X command may also be blocked, but you won't know that until you try it.&amp;nbsp; If the X command is blocked, you might have to talk to your SAS Admin.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS	XWAIT;
%LET	Path	=	I:\commercial\production\OPSI\documentation;
%cd(&amp;amp;Path);
x "dir *.xlsx,*.xls /od /t:w /b &amp;gt; dir_listing.txt";
FILENAME	Dir_List	"&amp;amp;Path\dir_listing.txt";

DATA	_NULL_;
	LENGTH	File_Name	$512.;

	INFILE	Dir_List	TRUNCOVER	END	=	_End_of_Listing;

	INPUT	File_Name	$;

	IF	_End_Of_Listing	THEN
		CALL	SYMPUTX('File_Name', File_Name, 'G');
RUN;

%PUT	NOTE:  The last spreadsheet to be modified is:  &amp;amp;File_Name;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result I get is as follows. This is the correct result for my system.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;NOTE:  The last spreadsheet to be modified is:  OPSI_Master_Dataset_List_2021-06-04.xlsx
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll note that I'm using a macro named "cd" (change directory) in the above code.&amp;nbsp; Here's the code for the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*-------------------------------------------------------------------------------*/
/*  Macro:	cd (Change Directory)
/*  Author:	Jim Barbour 
/*  Date:	11 September 2019
/*	Owner:	OptumInsight, Chart Review
/*	Info:	This macro changes the working directory at the operating system level.
/*          The macro functions in a manner similar to the "cd" command in DOS.
/*-------------------------------------------------------------------------------*/
/*									CHANGE LOG
/*-------------------------------------------------------------------------------*/
/*	Name:	Jim Barbour				Date:	11 September 2019
/*	Info:	Original implementation.
/*-------------------------------------------------------------------------------*/

%MACRO	cd(New_Dir);
	%GLOBAL	ReturnCode;

	%**	Change the working directory to a new directory.	**;
	%**	The new directory must include the path.			**;
	%LET	ReturnCode	=	%SYSFUNC(DLGCDIR("&amp;amp;New_Dir"));
%MEND	cd;

%**-----------------------------------------------------------------------------**;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 04:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745960#M233933</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-05T04:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Pull in the last modified file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745965#M233937</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89165"&gt;@Krysia24&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I receive two errors: 1.) Insufficient authorization to access PIPE.; 2.) Error in the filename statement.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This means that option NOXCMD is set, and you can't use the interfaces to the system (FILENAME PIPE, X, %SYSEXEC, SYSTEM function, CALL SYSTEM).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all your files are SAS dataset files, define a library for the directory, and pull the timestamps from DICTIONARY.TABLES.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have other types of files, use the file functions:&lt;/P&gt;
&lt;P&gt;FILENAME to assign a file reference to the directory&lt;/P&gt;
&lt;P&gt;DOPEN to open the directory&lt;/P&gt;
&lt;P&gt;in a DO loop from 1 to DNUM, use DREAD, FILENAME and FOPEN (or MOPEN) for the individual file and FINFO to retrieve the modification timestamp.&lt;/P&gt;
&lt;P&gt;You can find examples for similar code here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Modify-file-deletion-code-to-only-delete-files-older-than-5-days/m-p/636601#M189139" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Modify-file-deletion-code-to-only-delete-files-older-than-5-days/m-p/636601#M189139&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 06:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pull-in-the-last-modified-file/m-p/745965#M233937</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-05T06:53:33Z</dc:date>
    </item>
  </channel>
</rss>

