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

how do repeat the ID for every patient so that they have 11 instances they appear in the dataset. Some patients appear 3 4 7 or 11 times but I want everyone to be featured 11 times.

1 ACCEPTED SOLUTION

Accepted Solutions
Angel_Larrion
SAS Employee

The following code should work, it repeats the last observation of each id until there is 11 observations per id.

data want;
set have;
by id;
retain i 1;
if first.id then do; i=1; i=i+1; output; end;
else if last.id=0 and first.id=0 then do; i=i+1; output; end;


else if last.id then do; do until (i=12); i=i+1; output;

status=0; end; end;
drop i; run;

View solution in original post

4 REPLIES 4
Shmuel
Garnet | Level 18

What other variables are in your dataset? Should they be missing or with any initial value?

Please post an sample of your dataset.

 

Why do you want the IDs to be in 11 observations ? what is the logic or needs?

 

One way to do it is to select distinct IDs, replicate them to have 11 times each and then

remerge them with your dataset by ID and maybe some other variable (like a date).

sasgyro
Fluorite | Level 6

Yes, 

i need every instance repeated 11 times because I want the data to reflect the patient at different time intervals. the intervals for the experiment are the same for each patient and we took their vitals at each instance so there are other variables. however some patients died during before the full time length of experiment so there is no data for times above when they died. I still want to include them to 11 times for continuity and mark them as Status=0 for dead at this time interval. Im trying to put the data in a counting style.

 The data wu

ID.       T1T2StatusTrtNumberSizeZ

1

0

3

1

1

1

3

12.3

1

3

10

1

1

1

3

14.7

1

10

15

1

1

1

3

13.8

1

15

23

0

1

1

3

15.5

2

0

3

1

1

1

5

12.3

2

3

10

1

1

1

3

14.7

2

10

15

0

1

1

3

13.8

2

15

23

0

1

1

3

15.5

Shmuel
Garnet | Level 18

Looking at your table posted each observation have a unique KEY made of

ID T1 and T2.

What values should T1, T2 have in next added observations ?

 

Steps to result will be:

1) select distinct values of ID taken from current dataset

2) replicate IDs 11 times including  T1 T2 values creating a skeleton dataset

3) merging the skeleton with the current dataset by ID T1 T2

 

Angel_Larrion
SAS Employee

The following code should work, it repeats the last observation of each id until there is 11 observations per id.

data want;
set have;
by id;
retain i 1;
if first.id then do; i=1; i=i+1; output; end;
else if last.id=0 and first.id=0 then do; i=i+1; output; end;


else if last.id then do; do until (i=12); i=i+1; output;

status=0; end; end;
drop i; run;

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!
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
  • 4 replies
  • 1107 views
  • 3 likes
  • 3 in conversation