Help using Base SAS procedures

Regarding data

Reply
Frequent Contributor
Posts: 90

Regarding data

Hi,

I have a dataset with clam ,line and ind field.

1. when the whole clamno has the rev =Y  only, then need to select Y .

2.  When the clamno has the rev=Y and N , then need to select only 'N'.

data have;

input (CLAM LNNO IND) ($);

cards

;

12345 001 Y

12345 002 Y

12345 003 Y

23456 001 Y

23456 002 N

34567 001 Y

34567 002 N

34567 003 N

78968 001 Y

78968 002 Y

78968 003 Y

;

output should be:

12345  001 Y

12345  002 Y

12345  003 Y

23456 002  N

34567 002 N

34567 003 N

78968 001 Y

78968 002 Y

78698 003 Y

Thanks in Advance

Trusted Advisor
Posts: 1,300

Regarding data

data have;

input (CLAM LNNO IND) ($);

cards

;

12345 001 Y

12345 002 Y

12345 003 Y

23456 001 Y

23456 002 N

34567 001 Y

34567 002 N

34567 003 N

78968 001 Y

78968 002 Y

78968 003 Y

;

run;

proc sort data=have; by clam ind; run;

data want;

set have;

by clam ind;

if first.clam then del=0;

  if ind='N' then del+1;

  if ind='Y' and del>0 then delete;

drop del;

run;

Frequent Contributor
Posts: 90

Regarding data

It works well !! Thanks a lot !!!

Super User
Posts: 9,671

Regarding data

I want to know    when the whole clamno has the rev =N  only, What  you want to do?

Ksharp

Smiley Happy

Frequent Contributor
Posts: 90

Regarding data

Hi Sharp,

In that case we need to pick the whole clamno has the rev=N only.

For example,

clamno line rev

123    1      Y

123    2      Y

234   1       Y

234   2      N

567   1      N

567   2     N

OUTPUT SHOULD BE

123  1   Y

123  2   Y

234  2   N

567  1  N

567  2  N

Thanks.

PROC Star
Posts: 7,358

Regarding data

Thus, FriedEgg's code will work for that situation as well.  You really ought to give him credit for having answered the question.

Frequent Contributor
Posts: 90

Regarding data

Yes Sure Art !! He resolved the problem for me with in few minutes !!!

Thanks FriedEgg !!!

PROC Star
Posts: 7,358

Regarding data

I'm sure he will appreciate that.  But, if you don't indicate that the correct answer has been given, others will still spend time trying to provide you with a solution.

Ask a Question
Discussion stats
  • 7 replies
  • 172 views
  • 3 likes
  • 4 in conversation