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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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