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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 641 views
  • 0 likes
  • 2 in conversation