08-25-2013 02:10 AM
I have sas data
I want data3
I sort file 1, file 2 by in, then merge data 1 data 2 or merge data2 data1, results are different. What's happening? Any better way to get data 3? Thank you!
merge data 1 data 2;
merge data 2 data 1;
08-25-2013 02:20 AM
also, looks like i can not get data 3 by merging data1, data2 by variable in, no matter i merge data1 data 2, or merge data 2 data1.
But I don't know how to expand A to D,E,F, B to D,E, C to E, F ....in data 1.....
08-25-2013 02:50 AM
can you try using this piece of code.
i remember learning about such a situation in sas advanced prep guide:
do i =1 to num;
set _2(rename=(in = in1)) nobs=num point=i;
if in = in1 then output;
proc print data = _last_;
08-25-2013 01:45 PM
@Fugue's approach will be the one I would choose to use as well, cause we can take advantage of Proc SQL's native engine to do this Cartesian product kind of join by groups. However, if you have the curious mind (like most of us on this forum) on how to achieve the same results using Data step, then Hash() will most likely come into play.
input ID IN $;
input IN$ EX$;
if _n_=1 then do;
if 0 then set data1 data2;
declare hash h(dataset:'data2', multidata:'y');
do _n_=0 by 0 while (_n_=0);
Without involving Hash(), Data step + Index might have a shot as well, with a little more overhead I guess. @sachu69in's method will work , but with too much overhead.
Need further help from the community? Please ask a new question.