You don't need a sort order rule if the current master data set is (1) already in the desired order, and (2) all relevant values of the sort variable ("sortvar" below), are found at least once in the master data set.
You already stated that condition 1 is true. So assuming (2) is also true, then:
data want;
set master;
by key_var notsorted;
if _n_=1 then do;
declare hash h (dataset:'newdata',multidata:'Y');
h.definekey('key_var'); /* Was "definesortvar"*/
h.definedata(all:'Y');
h.definedone();
end;
output;
if last.key_var=1 and h.find()=0 then do until (h.find_next()^=0);
output;
end;
run;
Actually (2) doesn't have to be entirely true. What you really need is that the NEWDATA data set contains no key_var value not already in MASTER.
I've corrected some bad editing in my code above. Also this program assumes that dataset NEWDATA has all the same variables as MASTER. Otherwise extra variables from the last within-by-group observation in MASTER will be kept in the new observations added for the NEWDATA observations.
@sas-inquirer wrote:
@mkeintz This looks like an interesting approach and I am eager to try it, but I get an error (DATA STEP Component Object failure. Aborted during the COMPILATION phase.) From everything I read on google it would seem to point to a syntax error but unfortunately I have no experience with hash so am having trouble pin-pointing it. Any suggestions?
ANY time you get an error you should copy the log with all the procedure text and all notes, warnings as well as the message, open a text box on the forum with the </> icon and paste the text. The text box is important because SAS often includes diagnostic information that depends text behavior and the message windows on this forum will reformat pasted text which makes those diagnostics less useful or easy to follow.
With that said, look in the log or your code for something that includes two . in the syntax like this.that.something.
The error you get most easily generated that way.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.