DATA Step, Macro, Functions and more

code/retain value after trigger event

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

code/retain value after trigger event

ID Date Glucose_elevGluose_historical
1Jan-1200
1Mar-1200
1Oct-1311
1Feb-1401
1Jul-1511
2Feb-1211
2May-1311
2May-1511
2May-1611
3Jan-1200
3Feb-1311
3Jun-1301
3Feb-1401
3May-1501
3Nov-1511
3Dec-1511
3Dec-1501

 

I'm working on a dataset contains multiple subjects' longitudinal glucose level.  A typical scenario is, a high-risk patients' glucose level maintain normal until it reached the level of diabetics stage (Glucose_elev=1). Once the event triggered, even afterward his blood glucose went under control by medicine (Glucose_elve=0), we still consider this individual as "diabetic" (Glocuse_historical=1) after initial trigger event and ever after.  Some of the patients may never reach to diabetics stage during the study; others may be diabetic all the way, like subject #2. 

 

I would like to know how to code for Glucose_historical value. For one subject, before the trigger event, Glucose_histroical= 0, and on and after the trigger event, Glucose_historical=1. 

 

Thanks a million


Accepted Solutions
Solution
‎05-02-2017 05:17 PM
Trusted Advisor
Posts: 1,586

Re: code/retain value after trigger event

try next code:

 

data want;

 set have;

  by ID;

        retain glucode_historical;

       if first.id then glucose_historical=0;

       if glucose_elev=1 then glucose_historical=1;

 run;

View solution in original post


All Replies
Solution
‎05-02-2017 05:17 PM
Trusted Advisor
Posts: 1,586

Re: code/retain value after trigger event

try next code:

 

data want;

 set have;

  by ID;

        retain glucode_historical;

       if first.id then glucose_historical=0;

       if glucose_elev=1 then glucose_historical=1;

 run;

New Contributor
Posts: 2

Re: code/retain value after trigger event

Absolutely! Thanks so much, Shmuel!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 115 views
  • 1 like
  • 2 in conversation