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;

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 1054 views
  • 0 likes
  • 2 in conversation