<?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: Compare two Folders to see Changes. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841457#M332735</link>
    <description>&lt;P&gt;This macro will recursively scan a directory and produce an output table with a file listing and their corresponding md5 hashes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://core.sasjs.io/mp__hashdirectory_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__hashdirectory_8sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So if there is a change of any data in any of the files, you can can identify it by the change in the hash value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This feature is used by the SASjs "fs sync" function as documented here:&amp;nbsp; &lt;A href="https://cli.sasjs.io/fs" target="_blank"&gt;https://cli.sasjs.io/fs&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;This lets you synchronise a remote (SAS) directory with a local (desktop) one.&lt;/P&gt;</description>
    <pubDate>Sat, 29 Oct 2022 14:30:29 GMT</pubDate>
    <dc:creator>AllanBowe</dc:creator>
    <dc:date>2022-10-29T14:30:29Z</dc:date>
    <item>
      <title>Compare two Folders to see Changes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841363#M332681</link>
      <description>&lt;P&gt;I am looking to&amp;nbsp; compare two folder which contains same number of files, lets say 'folder1 ' and 'folder 2'.&amp;nbsp; I wan to run a program to&amp;nbsp; show if there is any changes in files between folders.&amp;nbsp; &amp;nbsp;We get a data every month which we will copy into folder 1 and folder 2 .Folder 1 used by some other purpose .&amp;nbsp; we use&amp;nbsp; Folder 2 for analysis. So we expect both folder1 and folder 2 have latest&amp;nbsp; and same data. I am thinking the process as mentioned like in the flow chart Image&amp;nbsp; ( Just initial thoughts of my brain may be there are certain things I did not considered). How can we do this? I do have the Idea and have macro to compare datasets in two folder ( which is last part of the flow chart).&amp;nbsp; Thank you for your thoughts and inputs.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1666981247111.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76728iC173D0322B7CE3AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1666981247111.png" alt="SASuserlot_0-1666981247111.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 18:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841363#M332681</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-10-28T18:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two Folders to see Changes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841368#M332684</link>
      <description>&lt;P&gt;Here is a quick check that uses some utility macros available from my GitHub stash. The code will get the macros for you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Get the macros */
filename code url "https://raw.githubusercontent.com/SASJedi/sas-macros/master/exist.sas";
%include code;

filename code url "https://raw.githubusercontent.com/SASJedi/sas-macros/master/fileattribs.sas";
%include code;

filename code url "https://raw.githubusercontent.com/SASJedi/sas-macros/master/findfiles.sas";
%include code;

filename code url "https://raw.githubusercontent.com/SASJedi/sas-macros/master/translate.sas";
%include code;

filename code clear;

/* Get list of files and attributes into 2 data sets */
%findfiles(s:/folder1,,work.folder1)
%findfiles(s:/folder2,,work.folder2)

/* Report the differences*/
proc sql;
select catx('/',coalesce(f1.path,f1.path),coalesce(f1.filename,f1.filename)) as File
		,case 
			when missing(f1.filename) then catx(' ','Missing from',f1.path)
			when missing(f2.filename) then catx(' ','Missing from',f2.path)
			else 'OK'
		end as Files
		,case 
			when f1.size &amp;lt;&amp;gt; f2.size then 'Differs'
			else 'OK'
		end as Size
		,case 
			when f1.CRDate &amp;lt;&amp;gt; f2.CRDate then 'Differs'
			else 'OK'
		end as CreationDate
		,case 
			when f1.ModDate &amp;lt;&amp;gt; f2.ModDate then 'Differs'
			else 'OK'
		end as ModDate
	from folder1 f1
		full join 
		  folder2 f2
	on f1.filename=f2.filename
	where f1.filename is null 
		or f2.filename is null 
		or f1.size    &amp;lt;&amp;gt; f2.size   
		or f1.CRDate  &amp;lt;&amp;gt; f2.CRDate 
		or f1.ModDate &amp;lt;&amp;gt; f2.ModDate
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;May the SAS be with you!&lt;BR /&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 19:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841368#M332684</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-10-28T19:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two Folders to see Changes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841393#M332696</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;.&amp;nbsp; It worked like magic. However I&amp;nbsp; have a&amp;nbsp; couple of questions.&lt;/P&gt;
&lt;P&gt;1. Find files macro what are these macro variables refers to?&lt;/P&gt;
&lt;PRE&gt;%macro findfiles(dir,ext,dsn,sub) / minoperator;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I am not sure about the dsn and sub and minoroperator do ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Present code going to the sub folder lever. How I can control if I don't want subfolder lever?&lt;/P&gt;
&lt;P&gt;In my case&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Folder 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Folder 2&lt;BR /&gt;Count.sas7bdat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Count.sas7bdat&lt;BR /&gt;Expenses .sas7bdat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Expenses .sas7bdat&lt;BR /&gt;loss.sas7bdat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;loss.sas7bdat&lt;BR /&gt;profit.sas7bdat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;profit.sas7bdat&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF00FF"&gt; SUB FOLDER&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With present code it going to subfolder and finding the sas7bdat files and comparing them.&amp;nbsp; However is it possible can I restrict not going to the subfolder? So with example above&amp;nbsp; I am expecting both folders are same when no changes&amp;nbsp; in the information . Show differ if any changes in the sas7bdat of main folder. Thank you.&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 21:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841393#M332696</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-10-28T21:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two Folders to see Changes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841452#M332733</link>
      <description>&lt;P&gt;For any of the macros I use here, just submit %macroname(?) to get syntax help in the log. For example, submitting this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%findfiles(?)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Gets this result in the log:&lt;/P&gt;
&lt;PRE&gt;NOTE:  *FINDFILES Documentation *******************************

       Produces a list of files with a specified extension in the log
       or optionally writes them to a dataset.

       SYNTAX: %FindFiles(dir,&amp;lt;ext,dsn,sub&amp;gt;)
          dir=fully qualified directory path
          ext=Space delimited list of file extensions (Optional, default is ALL)
          dsn=name of data set to store filenames (Optional, otherwise writes to log.)
          sub=look in subfolders? (Y|N default is Y)

       Example:
       %FindFiles(c:\temp, csv)
       %FindFiles(\\server\folder\, xls xlsx xlsm, work.myfiles)
       %FindFiles(s:/workshop,sas,work.pgm_files,N)

       *************************************************************&lt;/PRE&gt;
&lt;P&gt;As you can see above, the meaning and usage of each macro parameter is explained in the docs. To stop the macor from looking into subfolders, set the fourth parameter to N. So, for the example macro calls in the original response, you would use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%findfiles(s:/folder1,,work.folder1,N)
%findfiles(s:/folder2,,work.folder2,N)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;Mark&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 14:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841452#M332733</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-10-29T14:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two Folders to see Changes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841457#M332735</link>
      <description>&lt;P&gt;This macro will recursively scan a directory and produce an output table with a file listing and their corresponding md5 hashes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://core.sasjs.io/mp__hashdirectory_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__hashdirectory_8sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So if there is a change of any data in any of the files, you can can identify it by the change in the hash value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This feature is used by the SASjs "fs sync" function as documented here:&amp;nbsp; &lt;A href="https://cli.sasjs.io/fs" target="_blank"&gt;https://cli.sasjs.io/fs&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;This lets you synchronise a remote (SAS) directory with a local (desktop) one.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 14:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-two-Folders-to-see-Changes/m-p/841457#M332735</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2022-10-29T14:30:29Z</dc:date>
    </item>
  </channel>
</rss>

