BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
gandikk
Obsidian | Level 7

Hi,

 

I have 2 files on mainframe and both files have duplicate keys. 

 

first file:

 

ID KEY
1234 5678
3456 5678

 

second file:

 

KEY DATA
5678 abc.com
5678 ghi.com
5678 xyz.com

 

first and second files have duplicate keys. I need to repeat 3 records from 2nd file for each record in first file. My final output should be like this:

KEY DATA ID
5678 abc.com 1234
5678 ghi.com 1234
5678 xyz.com 1234
5678 abc.com 3456
5678 ghi.com 3456
5678 xyz.com 3456

 

Can I achieve this in SAS mainframe. 

 

Thanks for your help in advance!!

SAS@EMMAUS
1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
Ammonite | Level 13

You could use a DATA step merge or an SQL join. The join is simpler to code. 

First, crate the input data:

data h1;
	infile datalines dsd dlm=' ';
	input id  key;
datalines;
1234 5678
3456 5678
;

data h2;
	infile datalines dsd dlm=' ';
	input key data:$10.;
datalines;
5678 abc.com
5678 ghi.com
5678 xyz.com
;

Then do the join:


proc sql number;
select h2.*, Id
	from h1
	  inner join
         h2
	on h1.key=h2.key
	order by id, data
;
quit;
Check out my Jedi SAS Tricks for SAS Users

View solution in original post

1 REPLY 1
SASJedi
Ammonite | Level 13

You could use a DATA step merge or an SQL join. The join is simpler to code. 

First, crate the input data:

data h1;
	infile datalines dsd dlm=' ';
	input id  key;
datalines;
1234 5678
3456 5678
;

data h2;
	infile datalines dsd dlm=' ';
	input key data:$10.;
datalines;
5678 abc.com
5678 ghi.com
5678 xyz.com
;

Then do the join:


proc sql number;
select h2.*, Id
	from h1
	  inner join
         h2
	on h1.key=h2.key
	order by id, data
;
quit;
Check out my Jedi SAS Tricks for SAS Users

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 913 views
  • 1 like
  • 2 in conversation