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!

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
  • 2 replies
  • 2737 views
  • 0 likes
  • 2 in conversation