Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO RETAIN A VALUE IN A GROUP WHEN A CONDITION IS TRUE

Status
Not open for further replies.

kushiwije

Technical User
Jun 13, 2006
8
0
0
US
Hi I have this data set as below.

X Y
- -
1 A
1 A
1 A
1 D
1 J
2 B
2 B
2 D
2 C
2 C

Within a given value of X, when Y=D, I would like to reset the remaining values for Y to D. So the data set should look like this.

X Y
- -
1 A
1 A
1 A
1 D
1 D
2 B
2 B
2 D
2 D
2 D

Any help is greatly appreciated. Thanks!


 
Refer the following program, for desired output.

data t;
input X Y $;
cards;
1 A
1 A
1 A
1 D
1 J
2 B
2 B
2 D
2 C
2 C
3 A
3 D
4 A
4 B
4 D
4 C
4 D
4 R
4 R
;
run;


proc sort data =t;
by X;
run;


data t (drop=flag);
set t;

retain flag 0;
by x;
if first.x then flag = 0;
if y = 'D' then flag = 1;
if flag = 1 then y = 'D';
run;

sasbuddy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top