Hi guys,
I need some help with a code to delete the first row using unique ID, this is my data
ID | month | day | income |
1 | 1 | 1 | 20 |
1 | 1 | 2 | 40 |
1 | 3 | 1 | 21 |
1 | 3 | 2 | 56 |
1 | 3 | 3 | 54 |
1 | 4 | 4 | 23 |
4 | 1 | 1 | 5 |
4 | 1 | 2 | 3 |
4 | 2 | 3 | 4 |
4 | 2 | 4 | 5 |
4 | 3 | 5 | 65 |
6 | 2 | 1 | 86 |
6 | 2 | 2 | 34 |
6 | 3 | 3 | 23 |
9 | 7 | 1 | 65 |
9 | 7 | 2 | 54 |
9 | 8 | 3 | 99 |
9 | 8 | 4 | 12 |
9 | 8 | 5 | 33 |
9 | 9 | 6 | 65 |
9 | 9 | 7 | 23 |
13 | 1 | 1 | 12 |
13 | 2 | 2 | 65 |
13 | 2 | 3 | 32 |
I want to delete the rows marked in red, that is the first row of each unique ID, any ideas?
Jessica
require by statement.
DATA data_1 ;
SET data;
IF first.id then delete;
by id;
run;
Hi Jessica,
Use by group processing and if not first.id.
Regards,
Scott
Hi i did try this,
if first.id then delete;
but it does not work, am i doing anything wrong?
jessica
Hi Jessica
You have to sort and use a by statement before using if then delete. it should work just check for them still if you are facing problem please present the full code so that we can help. The statement you have mentioned above is fine.
Sudeer
i have done the sorting, it says "Variable FIRST.id is uninitialized" . I have a very simple code,
DATA data_1 ;
SET data;
IF first.id then delete;
run;
I got it guys! thanks a lot.
Please consider marking the question answered
sorry about that, i have marked it.
require by statement.
DATA data_1 ;
SET data;
IF first.id then delete;
by id;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.