BookmarkSubscribeRSS Feed
ravindra2
Fluorite | Level 6

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
;

7 REPLIES 7
Kurt_Bremser
Super User

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;
ravindra2
Fluorite | Level 6

can you please give me same thing in datastep

KentaMURANAKA
Pyrite | Level 9

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
Kurt_Bremser
Super User

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.

KentaMURANAKA
Pyrite | Level 9

Hi, Mr. KurtBremser:

 

Thank you for correcting my code. I agree with you. Thanks.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

s_lassen
Meteorite | Level 14

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2138 views
  • 3 likes
  • 5 in conversation