BookmarkSubscribeRSS Feed
hwangnyc
Quartz | Level 8

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

 

 

 

1 REPLY 1
ballardw
Super User

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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 692 views
  • 0 likes
  • 2 in conversation