BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hjjijkkl
Pyrite | Level 9

I have a table below and I want to create a table where the first 'ID' is 'test'' =1. If the first 'ID' isn't 'test' =1 then to have it in a separate column.

ID

date

test

1

6/7/18

1

1

8/12/28

1

2

5/4/18

3

3

6/20/18

1

3

10/4/18

2

4

5/8/18

3

4

7/23/18

3

5

3/9/18

1

5

7/4/18

1

5

11/20/18

1

 

I want the output to look like this

ID

date

test

Test1

Test2

1

6/7/18

1

1

 

1

8/12/28

1

 

1

2

5/4/18

2

 

2

3

6/20/18

1

1

 

3

10/4/18

2

 

2

4

5/8/18

3

 

3

4

7/23/18

3

 

3

5

3/9/18

1

1

 

5

7/4/18

1

 

5

11/20/18

1

 

1

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You missed to sign the first of ID=4.

Assuming data is sorted by ID then:

data want;
 set have;
  by ID;
      if first.id then test=1; else test=.;
run;
options missing=' ';

View solution in original post

1 REPLY 1
Shmuel
Garnet | Level 18

You missed to sign the first of ID=4.

Assuming data is sorted by ID then:

data want;
 set have;
  by ID;
      if first.id then test=1; else test=.;
run;
options missing=' ';

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 422 views
  • 0 likes
  • 2 in conversation