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

Dear Communities:

Greetings all!

I have data in the following format. 

Patient_ID  status  level  prediction

165201         0        0        0.0090204072  

165201         0        1        0.4682205524

165201         0        2        0.8122016298

165201         0        3        0.9751736188

165205         1        0        0.0081253999

165205         1        1        0.4420893893 

165205         1        2        0.7955942710

165205         1        3        0.9724900318

165208         2        0        0.0011220970

.

.                   .          .

165210      3          0        0.0980113921

165210      3          1        0.3479984169

165210      3          2        0.8289891254

165210      3          3        0.9509891254

 

...etc

Here I have two questions:

1. The "prediction" variable is the predicted cumulative probability for ordinal response 0 to 4(but 4 is reference due to the fact that it is not displayed in the table). But I want create a variable that change the cumulative probability into non-cumulative probability, that is, example for the first patient_Id with the 0 level: cumulative probability at level 1 minus at level 0,  for the first patient_Id with the second level: cumulative probability at level 2 minus at level 1,  for the first patient_Id with the third level: cumulative probability at level 3 minus at level 2, and finally one minus cumulative probability at level 3. The same procedure for all Patient Id.

Finally 

2. Based on the created variable in "1" I want to select a level with maximum probability so that I can get one probability value per patient_Id.

 

Thank you for your help!

I'm happy to justify it if it is not clear. 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    by patient_id;
    prev_pred=lag(prediction);
    if first.patient_id then do; 
        non_cumulative_prediction=prediction;
        output;
    end;
    else if not last.patient_id then do;
        non_cumulative_prediction=prediction-prev_pred;
        output;
    end;
    else if last.patient_id then do;
        non_cumulative_prediction=prediction-prev_pred;
        output;
        level=4;
        non_cumulative_prediction=1-prev_pred;
        output;
    end;
    drop prev_pred;
run;
proc summary nway data=want;
    class patient_id;
    var non_cumulative_prediction;
    output out=maximum max=max_prediction 
        maxid(non_cumulative_prediction(level))=level_at_max_pred;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
    set have;
    by patient_id;
    prev_pred=lag(prediction);
    if first.patient_id then do; 
        non_cumulative_prediction=prediction;
        output;
    end;
    else if not last.patient_id then do;
        non_cumulative_prediction=prediction-prev_pred;
        output;
    end;
    else if last.patient_id then do;
        non_cumulative_prediction=prediction-prev_pred;
        output;
        level=4;
        non_cumulative_prediction=1-prev_pred;
        output;
    end;
    drop prev_pred;
run;
proc summary nway data=want;
    class patient_id;
    var non_cumulative_prediction;
    output out=maximum max=max_prediction 
        maxid(non_cumulative_prediction(level))=level_at_max_pred;
run;
--
Paige Miller
Lijuu
Obsidian | Level 7

Dear 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 967 views
  • 0 likes
  • 2 in conversation