Deleting first row using ID

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Deleting first row using ID

Hi guys,

I need some help with a code to delete the first row using unique ID, this is my data

IDmonthdayincome
11120
11240
13121
13256
13354
14423
4115
4123
4234
4245
43565
62186
62234
63323
97165
97254
98399
98412
98533
99665
99723
131112
132265
132332

I want to delete the rows marked in red, that is the first row of each unique ID, any ideas?

Jessica


Accepted Solutions
Solution
‎06-12-2014 10:36 AM
Contributor
Posts: 29

Re: Deleting first row using ID

Posted in reply to Jessica98

require by statement.

DATA data_1 ;

SET data;

IF first.id then delete;

by id;

run;

View solution in original post


All Replies
Super Contributor
Posts: 297

Re: Deleting first row using ID

Posted in reply to Jessica98

Hi Jessica,

Use by group processing and if not first.id.

Regards,

Scott

Contributor
Posts: 30

Re: Deleting first row using ID

Posted in reply to Scott_Mitchell

Hi i did try this,

if first.id then delete;

but it does not work, am i doing anything wrong?

jessica

Contributor
Posts: 29

Re: Deleting first row using ID

Posted in reply to Jessica98

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

Contributor
Posts: 30

Re: Deleting first row using ID

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;

Contributor
Posts: 30

Re: Deleting first row using ID

Posted in reply to Jessica98

I got it guys! thanks a lot.

Super User
Posts: 19,855

Re: Deleting first row using ID

Posted in reply to Jessica98

Please consider marking the question answered Smiley Happy

Contributor
Posts: 30

Re: Deleting first row using ID

sorry about that, i have marked it. Smiley Happy

Solution
‎06-12-2014 10:36 AM
Contributor
Posts: 29

Re: Deleting first row using ID

Posted in reply to Jessica98

require by statement.

DATA data_1 ;

SET data;

IF first.id then delete;

by id;

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 1875 views
  • 6 likes
  • 5 in conversation