BookmarkSubscribeRSS Feed
BETO
Fluorite | Level 6

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

4 REPLIES 4
Reeza
Super User

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

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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 Smiley Happy

Tom
Super User Tom
Super User

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

AkilanR
Fluorite | Level 6

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

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1151 views
  • 1 like
  • 5 in conversation