BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jessica98
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jchapman
Calcite | Level 5

require by statement.

DATA data_1 ;

SET data;

IF first.id then delete;

by id;

run;

View solution in original post

8 REPLIES 8
Scott_Mitchell
Quartz | Level 8

Hi Jessica,

Use by group processing and if not first.id.

Regards,

Scott

Jessica98
Calcite | Level 5

Hi i did try this,

if first.id then delete;

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

jessica

Chrishi
Calcite | Level 5

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

Jessica98
Calcite | Level 5

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;

Jessica98
Calcite | Level 5

I got it guys! thanks a lot.

Reeza
Super User

Please consider marking the question answered Smiley Happy

Jessica98
Calcite | Level 5

sorry about that, i have marked it. Smiley Happy

Jchapman
Calcite | Level 5

require by statement.

DATA data_1 ;

SET data;

IF first.id then delete;

by id;

run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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