hi,
this is my detaset i want to create u warning that this dataset having duplicare record.
data lb;
input usubjid lbdtc $ 16. lbtptnum rbc wbc visit;
cards;
101 01-10-2018t10:15 1 1 1 1 86
101 01-10-2018t10:20 2 2 2 1.01
101 01-10-2018t10:20 2 2 2 1.01
;
Use SQL to get a count, and then proceed from that:
proc sql noprint;
select max(count) into :count from (select count(*) as count from lb group by usubjid,lbdtc,lbtptnum,rbc,wbc,visit);
quit;
data _null_;
if &count > 1 then put "WARNING";
run;
can you please give me same thing in datastep
Hi,
I don't understand "u warning", but how about this.
data lb;
input usubjid lbdtc $ 16. lbtptnum rbc wbc visit;
cards;
101 01-10-2018t10:15 1 1 1 1 86
101 01-10-2018t10:20 2 2 2 1.01
101 01-10-2018t10:20 2 2 2 1.01
;
run;
proc sort data=lb nodupkey dupout=dup;
by usubjid lbdtc lbtptnum rbc wbc visit;
run;
data _null_;
set dup;
call symputx("nobs", &sysnobs.);
run;
%macro chkobs;
data _null_;
set dup;
%if &&nobs. eq 0 %then %put ;
%else %if &&nobs. ne 0 %then %put %sysfunc(cats(WAR, NING:));
%mend chkobs;
%chkobs
Hi @KentaMURANAKA!
data _null_;
set dup;
call symputx("nobs", &sysnobs.);
run;
If dup is empty, the call symputx will never execute. The set is not necessary.
If you do want to use set dup, do it this way:
data _null_;
call symputx("nobs", nobs);
set dup nobs=nobs;
stop;
run;
The call symputx() is now executed before the EOF condition is encountered by the set statement, and only one data step iteration is run.
Hi, Mr. KurtBremser:
Thank you for correcting my code. I agree with you. Thanks.
Fix your data first. That date is incorrect. ISO dates have a specific format, this will make your life easier. Read up on the sdtm domain from CDISC, which as an industry, we should all be working with.
As for duplicate:
data want; set lb; by usubjid lbdtc; if first.lbdtc and not(last.lbdtc) then dup_flg="Y"; run;
Although I suspect you have lbtestcd and other variables to by group on as well.
If you get this data by reading from a file, and you know the file is sorted, you can do it like this:
data lb;
input usubjid lbdtc $ 16. lbtptnum rbc wbc visit;
if _infile_=lag(_infile_) then do;
error 'Duplicate record';
delete;
end;
cards;
101 01-10-2018t10:15 1 1 1 1 86
101 01-10-2018t10:20 2 2 2 1.01
101 01-10-2018t10:20 2 2 2 1.01
;run;
I used ERROR rather than writing a warning, because the ERROR statement will dump all variables in the log.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.