How to generate error in log for duplicte records
There are several ways to approach a problem like this. Here is one using the hash object
data testdata(drop=i j);
array vars var1-var3;
do i=1 to 100;
do j=1 to dim(vars);
vars[j]=rand('integer', 1, 10);
end;
output;
end;
run;
data test2;
if _N_ = 1 then do;
declare hash h();
h.defineKey('var1', 'var2', 'var3');
h.defineDone();
end;
set testdata;
rc=h.check();
if rc=0 then do;
put 'ERROR: Duplicate Row Detected in Observation No: ' _N_;
stop;
end;
if h.check() ne 0 then do;
output;
h.add();
end;
run;
How big is your data set?
There are several ways to approach a problem like this. Here is one using the hash object
data testdata(drop=i j);
array vars var1-var3;
do i=1 to 100;
do j=1 to dim(vars);
vars[j]=rand('integer', 1, 10);
end;
output;
end;
run;
data test2;
if _N_ = 1 then do;
declare hash h();
h.defineKey('var1', 'var2', 'var3');
h.defineDone();
end;
set testdata;
rc=h.check();
if rc=0 then do;
put 'ERROR: Duplicate Row Detected in Observation No: ' _N_;
stop;
end;
if h.check() ne 0 then do;
output;
h.add();
end;
run;
data testdata(drop=i j);
array vars var1-var3;
do i=1 to 100;
do j=1 to dim(vars);
vars[j]=rand('integer', 1, 10);
end;
output;
end;
run;
data _null_;
if 0 then set testdata;
declare hash h(dataset:'testdata',duplicate:'e');
h.defineKey('var1', 'var2', 'var3');
h.defineDone();
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.