Hello,
I need to run the following Kernel script and it works perfectly
#!/bin/bash
rm -f path1/log/*.log
rm -f path1/data/*.sas7bdat
rm -f path1/output/*.txt
cd path1/saspgm/
sas -sysparm '20250131#' path1/saspgm/HYFI_INTExpSF.sas -log path1/log/Hyfiprep_202501.log
sas -sysparm '20250228#' path1/saspgm/HYFI_INTExpSF.sas -log path1/log/Hyfiprep_202502.log
sas -sysparm '20250331#' path1/saspgm/HYFI_INTExpSF.sas -log path1/log/Hyfiprep_202503.log
sas -sysparm '20250430#' path1/saspgm/HYFI_INTExpSF.sas -log path1/log/Hyfiprep_202504.log
sas -sysparm '20250531#' path1/saspgm/HYFI_INTExpSF.sas -log path1/log/Hyfiprep_202505.log
sas -sysparm '20250630#' path1/saspgm/HYFI_INTExpSF.sas -log path1/log/Hyfiprep_202506.log
sas -sysparm '20250731#' path1/saspgm/HYFI_INTExpSF.sas -log path1/log/Hyfiprep_202507.log
When all the HYFI_INTExpSF.sas are executed, many output file are produced like:
path1/output/HyFIPrems202501.txt
path1/output/HyFIPrems202502.txt
path1/output/HyFIPrems202503.txt
path1/output/HyFIPrems202504.txt
path1/output/HyFIPrems202505.txt
path1/output/HyFIPrems202506.txt
path1/output/HyFIPrems202507.txt
Similar file already exist like:
path2/output/HyFIPrems202501.txt
path2/output/HyFIPrems202502.txt
path2/output/HyFIPrems202503.txt
path2/output/HyFIPrems202504.txt
path2/output/HyFIPrems202505.txt
path2/output/HyFIPrems202506.txt
path2/output/HyFIPrems202507.txt
Then when the output files are generated, I would like to execute a proc compare like
sas proc compare base=path1/output/HyFIPrems202501.txt compare =path2/output/HyFIPrems202501.txt;
run;
How to declare two libname in a Kernel Script and excute successive proc compare
PROC COMPARE compare SAS data sets, not flat files.
To be able to compare those files, you need to import them back again into SAS.
You could try to add a PROC COMPARE step for the data sets that is the basis for the files, depending on how they are created of course.
Maybe you could look at UNIX commands as diff and comm instead?
What you show is a shell script. Kernelscript is something completely different.
Maxims 14 & 15:
14: Use the Right Tool
Which, in this case, is the UNIX utility diff.
15: Know Your Playing Field
In this case, UNIX and the gazillion of powerful tools coming with it, of which diff is one.
Great programmers have already thrown their skills into giving you a superb text comparison tool; use it.
As Linus pointed out, proc compare does not compare flat txt file,it just compare sas dataset.
So firstly you need to change these txt file into sas dataset and then invoke PROC COMPARE.
data a; infile 'path1/output/HyFIPrems202501.txt' length=len; input x $varying200. len; run; data b; infile 'path2/output/HyFIPrems202501.txt' length=len; input x $varying200. len; run; proc compare base=a compare=b transpose brief; run;
We can't know what your SAS scripts like HYFI_INTExpSF.sas are actually doing but if the create text files then it's highly likely that they use a SAS table as source to create these text files.
As others already mentioned Proc Compare works on SAS tables and not text files. If your current scripts create these text files as a 1:1 export from SAS tables AND if these SAS tables are permanent, then you could of course write another SAS script that uses Proc Compare and compares the source SAS tables.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.