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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I Need a file merge solution possibly using SAS

Status
Not open for further replies.

mhw

MIS
Jul 2, 2001
13
US
I have 2 files, one a 'driver' file and the other the data master file. I'm using SAS version 8.0 on a mainframe using the MVS operating system. I simply want to choose all the records from the master file (File 2) where a particular field matches ANY of the values in the driver file (File 1).
It's that simple. The output would be a subset of the master file with the same length and record format.

File 1 (driver file)
---------------
Record length: 3
Format: fixed blocked RECFM=FB
Data:
123
234
345
456
567
678
789

File 2 (master file)
---------------
Record length: LRECL=354
Format: Variable Blocked RECFM=VB
Data:
matching field against driver file
|
|
V
...data here.....123....data here........
...data here.....678....data here........
...data here.....123....data here........
...data here.....345....data here........
...data here.....555....data here........
...data here.....777....data here........
...data here.....345....data here........
...data here.....123....data here........
...data here.....999....data here........
...data here.....789....data here........


The only records above that should NOT be output are the ones with 555, 777 and 999 in the matching column because they are not one of the values in the driver file.

I hope I have explained this thoroughly enough.

CAN THIS BE DONE WITH A SAS MERGE??? PLEASE HELP OUT IF YOU CAN.

THANKS,
MHW
 
Hi MHW!

Sort both files on the field in question:

proc sort data=driver;
by field1;

proc sort data=master;
by field1;

then merge on that field

data driver;
merge driver(in=indr) master;
by field1;
if indr;

this will keep only the records found in the driver file. Note that this will keep all of the field1 values in the driver file even if there is no matching record in the master file. If they should be in both then use:

data driver;
merge driver(in=indr) master(in=inma);
by field1;
if indr and inma

hth
Jeff Bridgham
bridgham@purdue.edu
 
Jeff,
Thanks for responding - I have tried this and it doesn't work. Not because it is coded wrong but there are a few things you need to know. One, I'm a COBOL programmer - I do not know SAS at all - I don't even know how to properly format the input and output fields in the SAS code. Second, one input file is fixed block and the other is variable block - does this matter to SAS? What I really need is the complete code given to me. I have other's examples but since I don't know the SAS syntax, any 'minor' change I try, for instance changing an IF statement to have 2 conditions instead of 1, makes the SAS code no longer work. I just need someone to give me some complete code that works for this. I've wasted a lot of time testing various changes in the SAS and I'm getting some but not all output in the PROC PRINT, but need it put into an output file specified in my JCL as well. As I said, I don't even know how to code this output process versus the PROC PRINT, so I just need the full SAS coded for me.
I hope you or someone else can provide this for me.

Thanks,
mhw
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top