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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.