Hello SAS community,
I would like your help in the following problem.
raw data:-
ID | seq | Idnum |
1 | 00 | 01 |
1 | 02 | 05 |
1 | 03 | 04 |
1 | 04 | 05 |
2 | 00 | 01 |
2 | 03 | 01 |
3 | 00 | 01 |
I would like to recode 00 as 01 when the subsequent code under same ID are >00 and keep the 00 when there are no subsequent codes.
The output can look like this.
ID | seq | Idnum |
1 | 01 | 01 |
1 | 02 | 05 |
1 | 03 | 04 |
1 | 04 | 05 |
2 | 01 | 01 |
2 | 03 | 01 |
3 | 00 | 01 |
Thank you for your help.
data have;
input ID (seq Idnum) ($);
cards;
1 00 01
1 02 05
1 03 04
1 04 05
2 00 01
2 03 01
3 00 01
;
data want;
set have;
by id;
if first.id and not last.id then seq='01';
run;
data have;
input ID (seq Idnum) ($);
cards;
1 00 01
1 02 05
1 03 04
1 04 05
2 00 01
2 03 01
3 00 01
;
data want;
set have;
by id;
if first.id and not last.id then seq='01';
run;
You are welcome 🙂 Have a good one!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.