Solved
New Contributor
Posts: 2

# code/retain value after trigger event

 ID Date Glucose_elev Gluose_historical 1 Jan-12 0 0 1 Mar-12 0 0 1 Oct-13 1 1 1 Feb-14 0 1 1 Jul-15 1 1 2 Feb-12 1 1 2 May-13 1 1 2 May-15 1 1 2 May-16 1 1 3 Jan-12 0 0 3 Feb-13 1 1 3 Jun-13 0 1 3 Feb-14 0 1 3 May-15 0 1 3 Nov-15 1 1 3 Dec-15 1 1 3 Dec-15 0 1

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
Posts: 1,827

## 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;

All Replies
Solution
‎05-02-2017 05:17 PM
Posts: 1,827

## 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.