Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAS help

Status
Not open for further replies.

Steward007

Technical User
Nov 19, 2012
2
0
0
US
HI,
1. I need to compare 2 files which has same data in it.
To check the data for beofre and after runs.
I have 2 files:
File1 before run
File2 after run
both have same columns and i need to write SAS code to comapre and find out whether there are mismatches in the 2 files.

How many are macthing and how many not matching and how many mismatches.
Can anyone help me??
 
Hi,

Considering the files you are talking about are flat files; I can give you a hint.
Follow the steps below,

1. Create a SAS dataset say beforeRun; by reading the complete single line into one variable (say txt_1) and create anohter varaible called obs_no which will have value of observation number into it i.e. _n_
2. Create another dataset say, afterRun by follwoing the same process steated above can create the varaibles (say txt_2) and obs_no.
(Remember you have read full record into single vairable; accordingly you need to specify the length of the variables)
3. create merged dataset of both of the above dataset, use have use the obs_no vairable as key for merging, the code will look like below

data merged_ds;
merge beforeRun after_Run;
by obs_no;
run;

4. Now you can compare the texts in txt_1 and txt_2 variables as below and create another dataset which will enlist the differences if any in those two files.


data differ;
set merged_ds;
if strip(txt_1) ne strip(txt_2) then output;
run;

**********************************

Hope this will help you.


sasbuddy
 
Worth checking out Proc Compare. I've used it a couple of times to check and it's a little unwieldy, but can simply compare ever value in ever record between the 2 datasets.
Chris.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top