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

SAS merge

Status
Not open for further replies.

solutions07

Programmer
Joined
Jun 7, 2007
Messages
2
Location
US
Hi All,

I have just started programming in SAS couple of days back and I am stuck at a point where I am not able to see a solution.

I have following data -

File lookup:
A B
20 1000
20 1001
20 1002
21 1003
21 1004
21 1005
22 1006
22 1007
23 1008
23 1009
23 1010

File Consumer Data:
CID A B
abc 20 1001
abc 20 1002
abc 21 1005
abc 22 1007
xyz 20 1002
xyz 21 1004
xyz 22 1006
xyz 23 1010

The out file should have:

ID A B Flag
abc 20 1000 0
abc 20 1001 1
abc 20 1002 1
abc 21 1003 0
abc 21 1004 0
abc 21 1005 1
abc 22 1006 0
abc 22 1007 1
abc 23 1008 0
abc 23 1009 0
abc 23 1010 0

xyz 20 1000 0
xyz 20 1001 0
xyz 20 1002 1
xyz 21 1003 0
xyz 21 1004 1
xyz 21 1005 0
xyz 22 1006 1
xyz 22 1007 0
xyz 23 1008 0
xyz 23 1009 0
xyz 23 1010 1

So basically, look up would be used like a library to merge on for each customer id and setting binary 0 or 1 based on the condition that consumer picked the tuple A B or not.

I can very easily think of solving it in JAVA/C++ but I want to learn a solution in SAS.

Thanks for all the help!


 
Solutions, here's an example...

Code:
data Lookup;
input A B;
datalines;
A B
20 1000
20 1001
20 1002
21 1003
21 1004
21 1005
22 1006
22 1007
23 1008
23 1009
23 1010
;
run;

data Consumer;
input CID $3. A B;
datalines;
abc 20 1001
abc 20 1002
abc 21 1005
abc 22 1007
xyz 20 1002
xyz 21 1004
xyz 22 1006
xyz 23 1010	
;
run;

proc sort data=Lookup;
	by A B;
run;

proc sort data=Consumer;
	By A B;
run;

data Merged;
merge  	Consumer(in=InCon)
		Lookup(in=InLookup);
by A B;

if InCon=1 and InLookup=1 then Binary=1; else Binary=0;
run;

Cheers

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top