DATA Step, Macro, Functions and more

Longitudinal data - cases with extra sessions

Reply
Contributor
Posts: 55

Longitudinal data - cases with extra sessions

I have longitudinal data that is in long form. The vast majority of my cases have 5 sessions. But there is a cases 8 sessions thus skewing things a bit and a case with 6. I’d like to be able to plot a timeline where the ending session is their last/final session. Here’s how I envision my data. Any suggestions or issues you think would occur with this would be greatly appreciated. Thanks!

ID

Session

Want

100

1

1

100

2

2

100

3

3

100

4

4

100

5

Last

101

1

1

101

2

2

101

3

3

101

4

4

101

5

Last

102

1

1

102

2

2

102

3

3

102

4

4

102

5

Last

103

1

1

103

2

2

103

3

3

103

4

4

103

5

5

103

6

6

103

7

7

103

8

Last

104

1

1

104

2

2

104

3

3

104

4

4

104

5

5

104

6

Last

 

 

 

Super User
Posts: 11,338

Re: Longitudinal data - cases with extra sessions

This will subset the data if sorted by id session:

data want;
   set have;
   by  id session;
   if session in (1,2,3,4) or Last.id;
run;

If you really want to add a variable as shown something like:

 

data want;
   set have;
   by  id session;
   length want $ 4.;
   if session in (1,2,3,4) then Want=put(session,best4.);
   else if last.id then Want='Last';
run;
Ask a Question
Discussion stats
  • 1 reply
  • 118 views
  • 0 likes
  • 2 in conversation