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

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

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;
PG
gpv2000
Calcite | Level 5
Yes it worked. Thank you very much. I am still learning to use do until . Your code did it quickly and neatly. Thanks.

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