09-11-2013 10:35 AM
There are two datasets TEMP and TEMP2
Obs A B C D
1 1 4 3 3
2 2 4 3 2
3 3 3 3 1
4 4 3 3 2
5 5 2 4 2
6 6 2 4 1
7 7 1 4 3
8 8 1 4 1
Obs A B C D
1 9 4 3 1
2 3 6 8 2
3 2 3 3 1
4 1 7 7 2
Question-.Write some data step code to merge the datasets TEMP and TEMP2 by variable A, just keeping the values of A that exist in dataset TEMP2, and keeping the values of B, C and D from dataset TEMP.
09-11-2013 10:57 AM
Here is to you, your classmates and your teacher!
proc sort data=temp; by a; run;
proc sort data=temp2; by a; run;
merge temp2(in=in2) temp(in=in1);
if in2 and in1;
proc print data=want noobs; run;
09-12-2013 01:21 AM
Thanks PG for the reply
but one question that you code will be containing values of A that are in Both Datasets as u mentioned the code line(if in2 and in1;)
But we want only those values of A that exist in dataset TEMP2, and keeping the values of B, C and D from dataset TEMP.
Can you please suggest.
09-12-2013 05:55 AM
As far as your first question you need to use IF IN2 as opposed toIF IN2 AND IN1;.
For your second question, let me put it this way. If you wanted to KEEP some variables from one dataset and KEEP some other variables from another dataset, what method do you think you would employ to do so?
09-12-2013 06:09 AM
I am confused in this.
Is it possible to select simultaneously some variables from one dataset and some varaibles from another datase while merging?
We can fulfill one condition at a time but not sure how to fulfill both conditions
09-12-2013 06:25 AM
You can either KEEP them as part of the sort procedures or alternately as a dataset option as shown below.
MERGE TEMP2(IN=IN2 KEEP=A B C D) TEMP(IN=IN1 KEEP= A);