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.
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!
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.