BookmarkSubscribeRSS Feed
DathanMD
Obsidian | Level 7

Hello mates;

I am new to SAS and I am stuck on my next step of data manipulation. I am not providing any code because I have no crew where to begin from with this logic.

I have data as shown below. I am interested in only keeping rows when the makes the initial unique change from the previous position. For example staff one first made the first ever change on 02jan2001 (from being cleaner to administrator). For staff 2, the first change ever was on 02jan2019 from Manager to Deputy_Director). For staff who have no change in position (for example staff 3), I would like to just retain the first row.

Data I have;

staff

Start_date

End_date

Job position

1

01jan2000

01jan2001

cleaner

1

02jan2001

01jan2002

administrator

1

02jan2002

01jan2003

Deputy_manager

1

02jan2004

01jan2005

Manager

2

01jan2000

02jan2004

Manager

2

03jan2004

03jan2006

Manager

2

02jan2006

01jan2009

Deputy_Director

2

02jan2009

01jan2012

Director

2

01jan2012

01jan2014

Unemployed

2

02jan2014

01jan2016

Director

3

01jan2000

06jan2000

unemployed

3

07jan2000

01jul2000

Unemployed

4

01jan2000

01jun2000

Cleaner

4

02jun2000

01aug2000

Manager

5

02aug2006

01jan2019

Director

 

Data I want;

Patient

Start_date

End_date

Job position

1

02jan2001

01jan2002

administrator

2

02jan2006

01jan2009

Deputy_Director

3

01jan2000

02jan2000

unemployed

4

01jan2000

01jan2000

Manager

 

Thank you.

 

Dathan Byonanebye

 

 

 

 

 

5 REPLIES 5
DathanMD
Obsidian | Level 7

Hello mates;

I am new to SAS and I am stuck on my next step of data manipulation. I am not providing any code because I have no crew where to begin from with this logic.

I have data as shown below. I am interested in only keeping rows when the makes the initial unique change from the previous position. For example staff one first made the first ever change on 02jan2001 (from being cleaner to administrator). For staff 2, the first change ever was on 02jan2019 from Manager to Deputy_Director). For staff who have no change in position (for example staff 3), I would like to just retain the first row.

Data I have;

staff

Start_date

End_date

Job_position

1

01jan2000

01jan2001

cleaner

1

02jan2001

01jan2002

administrator

1

02jan2002

01jan2003

Deputy_manager

1

02jan2004

01jan2005

Manager

2

01jan2000

02jan2004

Manager

2

03jan2004

03jan2006

Manager

2

02jan2006

01jan2009

Deputy_Director

2

02jan2009

01jan2012

Director

2

01jan2012

01jan2014

Unemployed

2

02jan2014

01jan2016

Director

3

01jan2000

06jan2000

unemployed

3

07jan2000

01jul2000

Unemployed

4

01jan2000

01jun2000

Cleaner

4

02jun2000

01aug2000

Manager

5

02aug2006

01jan2019

Director

 

Data I want;

Patient

Start_date

End_date

Job_position

1

02jan2001

01jan2002

administrator

2

02jan2006

01jan2009

Deputy_Director

3

01jan2000

02jan2000

unemployed

4

01jan2000

01jan2000

Manager

 

Thank you.

 

Dathan Byonanebye

 

 

 

 

 

andreas_lds
Jade | Level 19

@DathanMD Please don't double post questions.

PeterClemmensen
Tourmaline | Level 20

Why is Staff=5 not included? She has no change in position, though only 1 obs?

ed_sas_member
Meteorite | Level 14

Hi @DathanMD 

 

In addition to @PeterClemmensen 's question, how would like you manage the case of staff=3?

 

3

01jan2000

06jan2000

unemployed

3

07jan2000

01jul2000

Unemployed

 

- option 1: retrieve the first row (-> this is what you described in your initial post)

- option 2: collapse dates so that the end date appears as 01jul2000. In this case how would you manage time interruptions?

 

 

DathanMD
Obsidian | Level 7
Hi @PeterClemmensen


Option 2 is perfect pick for me. Thanks

Dathan

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
  • 5 replies
  • 588 views
  • 0 likes
  • 4 in conversation