BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BrinaLi
Fluorite | Level 6

Hello!

 

I am working with a dataset that has employee start and end dates. I want to collapse this employ table into one current row and overwrite the beginning date with the first date provided of the year in the begin_date column 

 

Here's a picture of what I'd like to do:

BrinaLi_0-1680419946752.png

 

I am working with over a million rows and would like to narrow it down to 2023, but hoping to be able to use this same code going into future years. 

 

Can anyone suggest how to do this?

 

thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
%let year = 2023;

data want;
set have;
by employee_id;
retain _start;
if first.employee_id then _start = .;
if _start =. and year(begin_date) = &year. then _start = begin_date;
if last.employee_id;
if _start ne . then begin_date = _start;
drop _start;
run;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User
%let year = 2023;

data want;
set have;
by employee_id;
retain _start;
if first.employee_id then _start = .;
if _start =. and year(begin_date) = &year. then _start = begin_date;
if last.employee_id;
if _start ne . then begin_date = _start;
drop _start;
run;
BrinaLi
Fluorite | Level 6

thank you! this worked!!!

Tom
Super User Tom
Super User

Can you explain what "narrow it down to 2023" means?

Do you want to only keep the observations where the end_date is greater than '01JAN2023'd ?

Or did you have some other interpretation in mind?

BrinaLi
Fluorite | Level 6

sure! I meant to only work with employee begin dates that started in 2023. Sorry for the confusion! I wanted to keep the most recent observation, it has an end date of  31-dec-99, but insert the earliest date that started in 2023 for the employee as the begin date for that row.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 547 views
  • 1 like
  • 3 in conversation