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

I have the following data:

ID Flag Date Details

1   N     1/1    abc

1   N     1/2    efg

1   Y     1/1    hij

2   N    1/3     lmo

 

This dataset is already sorted by ID, flag and date (ascending order) using proc sort. I want to now only output the last row in every ID, flag combination as follows:

ID Flag Date Details

1   N    1/2     efg

1   Y    1/1     hij

2   N    1/3    lmo

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Just use BY group processing.  You want the last one per ID FLAG group.

data want;
  set have;
  by ID Flag Date;
  if last.flag;
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Just use BY group processing.  You want the last one per ID FLAG group.

data want;
  set have;
  by ID Flag Date;
  if last.flag;
run;
aalluru
Obsidian | Level 7

that was easier than I thought. Thanks!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3453 views
  • 0 likes
  • 2 in conversation