Select specific rows

Reply
Occasional Contributor
Posts: 8

Select specific rows

I have following data with multiple recording from single patient

ID  date day value

BELF000000084785201111101164
BELF000000084785201112022172
BELF000016833470200701222226
BELF000016833470200705223398
BELF000016959442200804291242
BELF000016959442200808201126
BELF000016959442200902252302
BELF000016959442200904242320
BELF000017061714200806261152
BELF000017801424201108031298
BELF000017801424201109132252
BELF000017801424201110223234
BELF000024405407200802181232
BELF000024405407200803182190
BELF000024405410200701223380
BELF000024405410200702181506
BELF000024405410200703202480
BELF000024405410200706263346
BELF000024408114200704231296
BELF000024408114200707113294

I want to extract the patients with records in day 1  ; and  if day 1 and day 2 both available that also ;  and day1 day2 and day3 all available and this also. and through away other data. any sas help.

Super Contributor
Posts: 282

Re: Select specific rows

Hi,

Your data appears to be sorted, so how about:

data want(drop=gotSmiley Happy;

  set have;

  by id;

  if first.id then

  do;

    gotday1=0;

    gotday2=0;

  end;

  if day=1 then

  do;

    output;

    gotday1+1;

  end;

  else

    if day=2 and gotday1 then

  do;

    output;

    gotday2+1;

  end;

  else

    if day=3 and gotday2 then

      output;

run;

Regards,

Amir.

Message was edited by: Amir Malik - formatting.

Respected Advisor
Posts: 3,124

Re: Select specific rows

Hi,

I am not sure if I understand your rule correctly, if not, please provide a sample of your output data. To my understanding of your descritption, all  you need is those 'ID's with 'day=1'. If that is the case, the following code seems to work:

data have;

input ID :$20. date day value;

cards;

BELF000000084785 20111110 1 164

BELF000000084785 20111202 2 172

BELF000016833470 20070122 2 226

BELF000016833470 20070522 3 398

BELF000016959442 20080429 1 242

BELF000016959442 20080820 1 126

BELF000016959442 20090225 2 302

BELF000016959442 20090424 2 320

BELF000017061714 20080626 1 152

BELF000017801424 20110803 1 298

BELF000017801424 20110913 2 252

BELF000017801424 20111022 3 234

BELF000024405407 20080218 1 232

BELF000024405407 20080318 2 190

BELF000024405410 20070122 3 380

BELF000024405410 20070218 1 506

BELF000024405410 20070320 2 480

BELF000024405410 20070626 3 346

BELF000024408114 20070423 1 296

BELF000024408114 20070711 3 294

;

proc sort data=have;

by id day;

run;

data want;

do until (last.id);

  set have;

    by id day;

        if first.id and day=1 then _id=id;

        if id=_id then output;

end;

drop _id;

run;

proc print;run;

Haikuo

Ask a Question
Discussion stats
  • 2 replies
  • 196 views
  • 0 likes
  • 3 in conversation