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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register 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.

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