I need to examine the profile of each patient, but it is little complicated for a novice programmer like me.
If it is more than one negative DAYS,then I need to eliminate all of them except that nearest the origin(in below example record of -5 will be eliminated and -1 becomes 0). If there is an observation with days = 0 then all negative days can be eliminated. If there is no observation with DAYS=0 then change the negative DAYS to DAYS=0. Please note that in the exceptional case where there is only one DAYS for a patient then it is retained even if DAYS is negative (it will of course be changed to 0)
data have; input subject days grade; datalines; 12345 -5 0 /*deleted*/ 12345 -1 0 /* -1 becomes 0*/ 12345 12 1 12345 15 1 12345 21 1 12345 30 2 12345 35 2 23456 -3 0 /*deleted*/ 23456 -5 0 /*deleted*/ 23456 0 0 23456 9 1 23456 13 1 34567 -5 0 /* -5 becomes 0 */ 34567 8 1 34567 16 1 45678 -2 0 /* -2 becomes 0 */ run;
I need the output to look like below,
subject days grade
12345 0 0
12345 12 1
12345 15 1
12345 21 1
12345 30 2
12345 35 2
23456 0 0
23456 9 1
23456 13 1
34567 0 0
34567 8 1
34567 16 1
45678 0 0
I would greatly appreciate any suggestions.
I think this captures it:
data want;
do until(last.subject);
set have; by subject;
if days <= 0 then maxNeg = max(maxNeg, days);
end;
do until(last.subject);
set have; by subject;
if days = maxNeg then days = 0;
if days >= 0 then output;
end;
drop maxNeg;
run;
I think this captures it:
data want;
do until(last.subject);
set have; by subject;
if days <= 0 then maxNeg = max(maxNeg, days);
end;
do until(last.subject);
set have; by subject;
if days = maxNeg then days = 0;
if days >= 0 then output;
end;
drop maxNeg;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.