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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.