The SAS Output Delivery System and reporting techniques

REG: Observations in orignial order after merging

Reply
Contributor
Posts: 69

REG: Observations in orignial order after merging

I had merged the two datasets using the by variable and before merging I had sorted the datasets uisng proc sort:
Can anyone tell me the code so that observations should be in the previous order as in the base datasets,using the merge statement.
Frequent Contributor
Posts: 95

Re: REG: Observations in orignial order after merging

Posted in reply to Siddhartha
One easy solution is to record the original order in a separate variable before sorting and merging. Then, you can resort on this separate variable back to the original order.


data a;
set a;
order +1;
run;

proc sort data=a; by var1; run;
proc sort data=b; by var1; run;

data combined;
merge a b;
by var1;
run;

proc sort data=combined; by order; run;
Ask a Question
Discussion stats
  • 1 reply
  • 117 views
  • 0 likes
  • 2 in conversation