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

I am new to SAS and i am looking for help.
I have a dataset in wide format. Patients are followed for 20 days and each day i have tiredness measurement (20 variable per patient(day_1, day_2 ect..) and tiredness is a score between 0 and 100). I have a binary indicator (status)which is equal to 1 if tiredness is greater or equal to 80 and 0 otherwise. Using an array i would like to create a time to event variable which will take the value of the number of day when patient FIRST got a tiredness score greater or equal to 80 for those who have status=1 and the LAST number of day available in the follow up for those who have status=0.

Do you have sas script that can do it?
Thanks for your help

Romain

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@Romain69100 wrote:

Thank you for your quick reply :).

 

I am at home for the moment (France) so i will test it tomorrow.

For individuals with non missing missing values and and status=0 does the code will increment for time_to_status the last day of follow up?


It does this: "I want to create a new variable time_to_status which will take the following values: 4 , 3, 5,1 for individus 1,2,3,4 respectively."

--
Paige Miller

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

If I am understanding properly, then no array needed. You don't specifically state if you have 20 status variables, such as status1 status2 etc. but assuming you do have this

 

time_to_event = whichn(1,of status1-status20);

 

 

--
Paige Miller
Romain69100
Fluorite | Level 6
Thank you PaigeMiller for your reply. I have only one status variable. But i have 20 variable day_1, day_2 .... day_20 recording the tiredness score (one row per patient). Let say first patient have a tiredness score greater than 80 at day 4 so time to event will be equal to 4 for this subject. If the patient, during the 20 visits, do not reach a score greater to 80 , the time to event will correspond to the last day of follow up.
PaigeMiller
Diamond | Level 26

Okay so your description to me is contradictory and not making sense. You said earlier "I have a binary indicator (status)which is equal to 1 if tiredness is greater or equal to 80 and 0 otherwise." Wouldn't there be 20 of these? But now you say the first occurrence of 80 is in day 4 but don't mention the status variable at all.

 

The best thing to do is to show us a small portion of the data, following these instructions, or type in SAS data step code by yourself — and not via any other method. You can, if you want, assume there are only 5 time periods, we just need to see the layout of the data.

--
Paige Miller
Romain69100
Fluorite | Level 6

Sorry  for my english and if i am not clear (English is not my mother tongue).

Please find attached the file below.

I want to create the time to status variable as it appear in the file.

 

Thanks again 

PaigeMiller
Diamond | Level 26

I realize you are new here, but I specifically stated the format needed, and that other formats are not acceptable. Many of us (including me) will not download attachments. Please show us SAS data step code that will reproduce a portion of your data set.

--
Paige Miller
Romain69100
Fluorite | Level 6

Here is the data step to create the table:

data tiredness;

input ID $ Day_1 Day_2 Day_3 Day_4 Day_5 status;

datalines;

1 50 60 70 85 20 1

2 10 20 30   .    .  0

3 20 40 50 55 60 0

4 85 79 100 120 130 1

;

run;

 

I want to create a new variable time_to_status which will take the following values:

4 , 3, 5,1 for individus 1,2,3,4 respectively.

 

PaigeMiller
Diamond | Level 26

Great! Thank you. 

 

data want;
    set tiredness;
    array d day_1-day_5;
    do i=1 to dim(d);
        if d(i)>=80 then do;
            time_to_event=i;
            leave;
        end;
        if time_to_event=. then time_to_event=n(of d(*));
    end;
run;
--
Paige Miller
Romain69100
Fluorite | Level 6

Thank you for your quick reply :).

 

I am at home for the moment (France) so i will test it tomorrow.

For individuals with non missing missing values and and status=0 does the code will increment for time_to_status the last day of follow up?

PaigeMiller
Diamond | Level 26

@Romain69100 wrote:

Thank you for your quick reply :).

 

I am at home for the moment (France) so i will test it tomorrow.

For individuals with non missing missing values and and status=0 does the code will increment for time_to_status the last day of follow up?


It does this: "I want to create a new variable time_to_status which will take the following values: 4 , 3, 5,1 for individus 1,2,3,4 respectively."

--
Paige Miller
Romain69100
Fluorite | Level 6
Thanks a lot, i tested your code and it works well!!
Have a nice day
PaigeMiller
Diamond | Level 26

@Romain69100 

Great. Please mark the reply with the working code as correct, instead of marking the reply with a brief comment as correct.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1678 views
  • 1 like
  • 2 in conversation