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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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