<?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 Want to delete 3 year old files only from a folder in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302291#M64110</link>
    <description>&lt;P&gt;Dear Experts ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to delete the files which are 3 year and above old . If I use the code which I attached this will delete the files which I need and its deleting the files which are in other formats also. But I need only the specified files to be deleted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me on this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Manesh&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic;
    %macro delete_year_files_in_folder(folder);
       filename filelist "&amp;amp;folder";
       data _null_;
	      dir_id = dopen('filelist');
          total_members = dnum(dir_id);
          do i = 1 to total_members;  
           member_name = dread(dir_id,i);

		datestring = scan(member_name,4,'_');
		
		month = input(substr(datestring,5,2),best.);
		day = input(substr(datestring,5,2),best.);
		year = input(substr(datestring,1,4),best.);
		date = mdy(month, day, year);
			 if intnx('year', today(),-3,'S') &amp;gt; date then do;
              file_id = mopen(dir_id,member_name,'i',0);
              if file_id &amp;gt; 0 then do; 
                freadrc = fread(file_id);
                rc = fclose(file_id);
                rc = filename('delete',member_name,,,'filelist');
                rc = fdelete('delete');
             end;
             rc = fclose(file_id);
          end;
          end;
          rc = dclose(dir_id);
       run;
    %mend;


	%delete_year_files_in_folder(C:\Users\UCS1MKP\Desktop\check)


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Oct 2016 10:03:01 GMT</pubDate>
    <dc:creator>ambadi007</dc:creator>
    <dc:date>2016-10-04T10:03:01Z</dc:date>
    <item>
      <title>Want to delete 3 year old files only from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302291#M64110</link>
      <description>&lt;P&gt;Dear Experts ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to delete the files which are 3 year and above old . If I use the code which I attached this will delete the files which I need and its deleting the files which are in other formats also. But I need only the specified files to be deleted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me on this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Manesh&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic;
    %macro delete_year_files_in_folder(folder);
       filename filelist "&amp;amp;folder";
       data _null_;
	      dir_id = dopen('filelist');
          total_members = dnum(dir_id);
          do i = 1 to total_members;  
           member_name = dread(dir_id,i);

		datestring = scan(member_name,4,'_');
		
		month = input(substr(datestring,5,2),best.);
		day = input(substr(datestring,5,2),best.);
		year = input(substr(datestring,1,4),best.);
		date = mdy(month, day, year);
			 if intnx('year', today(),-3,'S') &amp;gt; date then do;
              file_id = mopen(dir_id,member_name,'i',0);
              if file_id &amp;gt; 0 then do; 
                freadrc = fread(file_id);
                rc = fclose(file_id);
                rc = filename('delete',member_name,,,'filelist');
                rc = fdelete('delete');
             end;
             rc = fclose(file_id);
          end;
          end;
          rc = dclose(dir_id);
       run;
    %mend;


	%delete_year_files_in_folder(C:\Users\UCS1MKP\Desktop\check)


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Oct 2016 10:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302291#M64110</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2016-10-04T10:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: Want to delete 3 year old files only from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302293#M64112</link>
      <description>&lt;P&gt;I would suggest that you would be better off talking to your IT group and get them to archive files over 3 years old. &amp;nbsp;They will have some automated process for such a task and it provides a safety net for you, both in the fact that you are not deleting files (which can go wrong - badly), and if you ever want to go back to those files (which is 99% probabilty after you delete them) then you can retrieve from archive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for your code, can you not put in another if statement, say for .txt only:&lt;/P&gt;
&lt;P&gt;if index(upcase(member_name),".TXT") then do;&lt;/P&gt;
&lt;P&gt;...delete&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 10:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302293#M64112</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-04T10:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Want to delete 3 year old files only from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302294#M64113</link>
      <description>&lt;P&gt;What do you mean by "specified"? Apply&amp;nbsp;to the name standard of date in the filename?&lt;/P&gt;
&lt;P&gt;Why are month and day picked&amp;nbsp;from the same location, can't be right.&lt;/P&gt;
&lt;P&gt;Perhaps some&amp;nbsp;files doesn't have a valid date in the name, and missing is a smaller value than three years from now.&lt;/P&gt;
&lt;P&gt;Do you get any warnings in the log for the assignment&amp;nbsp;statements?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 10:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302294#M64113</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-04T10:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Want to delete 3 year old files only from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302297#M64116</link>
      <description>Hi The file name is&lt;BR /&gt;SFRE_BIL_SIT_20160812_134317_PAM_FILES1.zip&lt;BR /&gt;So from here I am only taking the year part from the file name. But When I run the program it is deleting the other files which are in different format for example the files like one.txt or two.zip something like this .&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 04 Oct 2016 10:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302297#M64116</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2016-10-04T10:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Want to delete 3 year old files only from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302298#M64117</link>
      <description>Hi The file name is&lt;BR /&gt;SFRE_BIL_SIT_20160812_134317_PAM_FILES1.zip&lt;BR /&gt;So from here I am only taking the year part from the file name. But When I run the program it is deleting the other files which are in different format for example the files like one.txt or two.zip something like this .&lt;BR /&gt;</description>
      <pubDate>Tue, 04 Oct 2016 10:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302298#M64117</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2016-10-04T10:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Want to delete 3 year old files only from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302300#M64119</link>
      <description>&lt;P&gt;So your problem can basically be solved by what I pointed out in my previous post.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 10:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302300#M64119</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-04T10:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Want to delete 3 year old files only from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302307#M64124</link>
      <description>&lt;P&gt;Yes I am getting a note like&lt;/P&gt;&lt;P&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;/P&gt;&lt;P&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please&amp;nbsp;advice me&amp;nbsp;how to give a standard name to the files which I need to delete ?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 10:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302307#M64124</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2016-10-04T10:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Want to delete 3 year old files only from a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302309#M64125</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76823"&gt;@ambadi007&lt;/a&gt; wrote:&lt;BR /&gt;Hi The file name is&lt;BR /&gt;SFRE_BIL_SIT_20160812_134317_PAM_FILES1.zip&lt;BR /&gt;So from here I am only taking the year part from the file name. But When I run the program it is deleting the other files which are in different format for example the files like one.txt or two.zip something like this .&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If code like this doesn't work like you expected, comment the part that actually does something (in yout case, the delete action) and instead create a dataset that contains all relevant variables, and use output instead of the action. Then inspect your dataset, and you will be able to follow all the conditions.&lt;/P&gt;
&lt;P&gt;If that is not granular enough, use put _all_ at the relevant stages of your decision process. Then you find the status of all variables at every intersting step in the log.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 11:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-delete-3-year-old-files-only-from-a-folder/m-p/302309#M64125</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-04T11:12:15Z</dc:date>
    </item>
  </channel>
</rss>

