0

I need to compare two text files (in different directories) to see if they are different (a binary result is fine). Given a dataset such as the one below, is this possible within a datastep?

Pathname
c:\one\text1.txt
c:\two\text1.txt
c:\one\text2.txt
c:\two\text2.txt

Alternatively, macro code would be fine! Checksum is a possibility, I need the code to run in both windows & unix.

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
  • If you can read the contents of the whole file into one variable, SAS has an `md5()` function you could use. But I'm not sure how to read a file that way. – itzy Aug 13 '12 at 15:06

2 Answers2

1

Pass it to the command line (via a pipe fileref)

In Windows, use the 'comp' command.

In Unix, use the 'diff' command.

Chris J
  • 7,549
  • 2
  • 25
  • 25
0

Thanks to Chris J - this worked for me:

%let root=%sysfunc(pathname(work));
data;
file "&root.\x.txt";
put 'xxx';
data;
file "&root.\x2.txt";
put 'xx x';
filename x pipe "diff &root.\x.txt &root.\x2.txt ";
data;
infile x;
input x $1000.;
run;
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124