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
What does your code look like? How doesn't it work?
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
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
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.