## Four if statements in one data step

Regular Contributor
Posts: 240

# Four if statements in one data step

HI I have a data step that I'm working on it has 4 if statement  but it's not giving me what I need  here is how the data looks...what I need is the status column define in a if statement   Thanks

Id.       Date.                Sdchedule Replen \$.       Actual Replen Amoint.     Add Replen\$.    Status

1.        11/20/13.                    100.                                100.                                0.               Correct

2.        11/20/13.                   100.                                 80.                                 0.               Short

3.            11/20/13.                  100.                                00.                               100.              Wrong Replen

4.             11/20/13.                  100.                                00.                                00.                 Missed Replen

Super User
Posts: 23,711

## Re: Four if statements in one data step

What does your code look like? How doesn't it work?

Super Contributor
Posts: 464

## Re: Four if statements in one data step

i am pretty sure it is something with the length of "status" defined in the first if.

if status='Correct' then the other status values get truncated. This is just my guess

Super User
Posts: 8,093

## Re: Four if statements in one data step

What did you try?  Can you explain the rules rather than just giving examples? I could only guess as to what the rule is for number 2 and didn't even try for numbers 3 and 4.

Here is code that gets the first two correct and marks both of the last two as Wrong.

data have ;

length id date schedule actual add 8 expected status \$20 ;

informat date mmddyy. ;

format date yymmdd10.;

input id date schedule actual add expected & ;

if schedule = actual then status='Correct';

else if 0 < actual < schedule and add=0 then status='Short';

else status = 'Wrong';

cards;

1. 11/20/13 100. 100. 0. Correct

2. 11/20/13 100.  80.  0. Short

3. 11/20/13 100. 00. 100. Wrong Replen

4. 11/20/13 100. 00. 00. Missed Replen

run;

Obs    id          date    schedule    actual    add    expected         status

1      1    2013-11-20       100        100       0    Correct          Correct

2      2    2013-11-20       100         80       0    Short            Short

3      3    2013-11-20       100          0     100    Wrong Replen     Wrong

4      4    2013-11-20       100          0       0    Missed Replen    Wrong

Occasional Contributor
Posts: 17

## Re: Four if statements in one data step

Hi Beto,

I am not prettly clear on your question. Please see the below script to arrive 'status' column

DATA OUTPUT;

INPUT ID DATE SCHEDULE ACTUAL ADD  ;

LENGTH STATUS \$25. ;

INFORMAT DATE MMDDYY8. ;

FORMAT DATE MMDDYY8. ;

IF ACTUAL NE 0 THEN DO;

IF SCHEDULE NE ACTUAL THEN STATUS = 'SHORT';

ELSE STATUS = 'CORRECT';

END;

ELSE DO;

IF SCHEDULE NE ADD THEN STATUS = 'MISSED REPLEN';

ELSE STATUS = 'WRONG REPLEN';

END;

DATALINES;

1.  11/20/13  100.  100.  0.

2.  11/20/13  100.   80.   0.

3.  11/20/13  100.  00.    100.

4.  11/20/13  100.  00.  00.

RUN;

Hope this will meets your requirement

Discussion stats
• 4 replies
• 255 views
• 1 like
• 5 in conversation