turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Row by row comparison and update previous row text...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

a month ago - last edited a month ago

Thanks for your support in advance

Below is the input

INPUT | ||

sno | txt | sq |

1 | a | 1 |

1 | b | 2 |

1 | u | 3 |

1 | u | 4 |

1 | u | 5 |

1 | c | 6 |

2 | a | 1 |

2 | b | 2 |

3 | a | 1 |

3 | b | 2 |

3 | u | 3 |

3 | c | 4 |

3 | u | 5 |

3 | u | 6 |

Need output as shown below variable txt with 'u' observation with previous value.& current value i.e 'u' as shown in **BOLD**.

OUTPUT | ||

sno | txt | sq |

1 | a | 1 |

1 | b | 2 |

1 |
bu |
3 |

1 |
bu |
4 |

1 |
bu |
5 |

1 | c | 6 |

2 | a | 1 |

2 | b | 2 |

3 | a | 1 |

3 | b | 2 |

3 |
bu |
3 |

3 | c | 4 |

3 |
cu |
5 |

3 |
cu |
6 |

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

a month ago

```
data have;
input sno txt : $8. sq;
datalines;
1 a 1
1 b 2
1 u 3
1 u 4
1 u 5
1 c 6
2 a 1
2 b 2
3 a 1
3 b 2
3 u 3
3 c 4
3 u 5
3 u 6
;
data want;
set have;
by sno;
length k $8;
if first.sno then call missing(k);
retain k;
if txt='u' then txt=cats(k,txt);
else k=txt;
drop k;
run;
```

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to novinosrin

2 weeks ago

Thank you

now i have couple of more records with below instance sno 4,5

INPUT

sno txt sq

1 a 1

1 b 2

1 u 3

1 u 4

1 u 5

1 c 6

2 a 1

2 b 2

3 a 1

3 b 2

3 u 3

3 c 4

3 u 5

3 u 6

4 u 1

4 b 2

5 a 1

5 u 2

5 b 3

Need output as shown below variable txt with 'u' observation for sno 4 and 5 as well

OUTPUT

sno txt sq

1 a 1

1 b 2

1 bu 3

1 bu 4

1 bu 5

1 c 6

2 a 1

2 b 2

3 a 1

3 b 2

3 bu 3

3 c 4

3 cu 5

3 cu 6

4 bu 1

4 b 2

5 a 1

5 bu 2

5 b 3

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

a month ago

@krc The solution is straight forward and simple with retain, concatenate and reset logic

If the question is answered, you could mark and close the thread

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

a month ago

If the length of your current TXT field is 1 (proc contents or other method methods examining the table to tell) then your solution will require setting a length for the variable to hold the longest expected value.

This would look something like:

data want; length txt $ 2; set have; /* other code*/ run;

Note that if the length statement is after the Set you'll get a warning that you can't change existing variable length.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

Thank you

now i have couple of more records with below instance sno 4,5

INPUT

sno txt sq

1 a 1

1 b 2

1 u 3

1 u 4

1 u 5

1 c 6

2 a 1

2 b 2

3 a 1

3 b 2

3 u 3

3 c 4

3 u 5

3 u 6

4 u 1

4 b 2

5 a 1

5 u 2

5 b 3

Need output as shown below variable txt with 'u' observation for sno 4 and 5 as well

OUTPUT

sno txt sq

1 a 1

1 b 2

1 bu 3

1 bu 4

1 bu 5

1 c 6

2 a 1

2 b 2

3 a 1

3 b 2

3 bu 3

3 c 4

3 cu 5

3 cu 6

4 bu 1

4 b 2

5 a 1

5 bu 2

5 b 3