BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello,

I currently have data that looks like this.

NAME OFFICE_ID YEAR_QTR END_TERM
BILL 1 20021 20024
BILL 2 20021 20022
JOE 3 20021 20033
JOE 4 20021 20031

For each person, I would like to flag the Office_ID with the latest End_Term, so my data would look something like this

NAME OFFICE_ID YEAR_QTR END_TERM FLAG
BILL 1 20021 20024 1
BILL 2 20021 20022 0
JOE 3 20021 20033 1
JOE 4 20021 20031 0

I would like to achieve this using PROC SQL, but any tips are welcome. Thank you very much. I am using SAS 9.1.
1 REPLY 1
ChrisNZ
Tourmaline | Level 20
Generally speaking, SQL is a much poorer query and manipulation language than the sas language. In this case tho, I think you need 2 steps no matter what, so SQL is fine. This should do:

select a.*, a.OFFICE_ID=b.OFFICE_ID as FLAG
from TEST a,
(select NAME, OFFICE_ID
from TEST
group by NAME
having END_TERM=max(END_TERM)) b
where a.NAME=b.NAME;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 619 views
  • 0 likes
  • 2 in conversation