MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SAS MERGE Issue - Please Recommend!

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Bharath.AK
Beginner


Joined: 13 Jul 2007
Posts: 34
Topics: 10
Location: Los Angeles

PostPosted: Thu Feb 18, 2010 3:20 am    Post subject: SAS MERGE Issue - Please Recommend! Reply with quote

Hi,

I have two datasets:

Dataset A:
Key: Misc:
AMC WIRE
AMC WIRE
AMC WIRE
ABD XXXX


Dataset B:
Key: Misc:
AMC NETTING

I need to merge these two datasets BY the variable KEY so that the output dataset should contain all the observations in Dataset A and the matched observations should have MISC variable updated to what we have in Dataset B:

Output:
Key: Misc:
AMC NETTING
AMC NETTING
AMC NETTING
ABD XXXX


I am doing the merge as below:
Code:
Data Dataset_Perm;
Merge     DatasetA        (IN=A)
              DatasetB       (IN=AP) ;
By          Key;
IF B AND NOT A THEN DELETE;
Run;


But I am getting the output dataset as:
Key: Misc:
AMC NETTING
AMC WIRE
AMC WIRE
ABD XXXX


Only the first matched observation is being updated with the new MISC value and the rest are not being updated.

Please advice me how to go about it.

Thanks,
BK
Back to top
View user's profile Send private message
expat
Intermediate


Joined: 01 Mar 2007
Posts: 475
Topics: 9
Location: Welsh Wales

PostPosted: Thu Feb 18, 2010 9:37 am    Post subject: Reply with quote

I'm not sure that you can do what you want with the two variable names being the same.

I would change the variable name on one file and then use the code below
The code assumes that the SAS dataset already exists, if not then just create it with the different variable name.
Code:
PROC SORT DATA=DATASETA NODUPS;
  BY KEY;
  RUN;
 
DATA DATASETB;
  SET DATASETB;
  RENAME MISC = MISC2;
  RUN;
 
PROC SORT DATA=DATASETB NODUPS;
  BY KEY;
  RUN;

DATA DATASET_AB;
  MERGE   DATASETA (IN=IN1)
          DATASETB (IN=IN2);
  BY KEY;
  IF IN1 AND IN2 THEN MISC = MISC2;
  DROP MISC2;
  RUN;


Input for DATASETA
Code:
123  ABD       
123  DEF       
456  HDH       
331  PPO       
123  ASS

Input for DATASETB
Code:
123  XXX       

Output shows
Code:
KEY    MISC
           
123    XXX
123    XXX
123    XXX
331    PPO
456    HDH

_________________
If it's true that we are here to help others,
then what exactly are the others here for ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group