so here's is my coding. from my data the first totalprice*unit =70MYR. when I run it, the discount I get is 4.90MYR. If is calculate it manually, the discount that I should get is 3.50MYR. Does anyone know how to do it correctly?
DATA Payment;
SET combined;
LENGTH total $ 10;
LABEL total='Total Price (RM)'
after='Total Price after Discount (RM)'
dis='Discount (RM)'
fee='Courier Fee (RM)'
net='Net Amount (RM)';
total='Price (RM)'n*unit;
IF total>=20 THEN after=total-dis;
ELSE dis=total*0.05;
IF total>=30 THEN dis=total*0.07;
ELSE dis=total*0.00;
after=total-dis;
net=after+5;
RUN;
PROC PRINT DATA=Payment label;
TITLE 'Monarch Online Shop';
FOOTNOTE 'STAY AT HOME AND STAY SAFE';
RUN;
Think through your conditional statements using 70MYR. Are they what you intend?
From your logic, total = 70 goes into the first IF statement (since 70 is >= 20), so AFTER is set to total-dis. And total =70 also goes into the second IF statement (since 70 is >= 30), so DIS is set to 70 * 0.07. So from your logic, 4.90MYR is the correct result.
Is DIS = TOTAL * 0.05 supposed to be applied when Total is >= 20? Right now, since you have that in an ELSE statement, it won't be applied.
Think through your conditional statements using 70MYR. Are they what you intend?
From your logic, total = 70 goes into the first IF statement (since 70 is >= 20), so AFTER is set to total-dis. And total =70 also goes into the second IF statement (since 70 is >= 30), so DIS is set to 70 * 0.07. So from your logic, 4.90MYR is the correct result.
Is DIS = TOTAL * 0.05 supposed to be applied when Total is >= 20? Right now, since you have that in an ELSE statement, it won't be applied.
Buyer that spent more than RM20 (excluding courier fee) will receive 5% discount, and buyer that spent more than RM30 (excluding courier fee) will receive 7% discount. Using SAS, calculate the net amount that the buyer needs to pay for that order (cost of item + courier fee). This is the question I got.
How can I make that if total=70, it only use either one of the statement?
@IdlanHnf Try this:
IF total>=30
THEN dis=total*0.07;
ELSE IF total>=20
THEN dis=total*0.05;
ELSE dis=total*0.00;
after = total-dis;
thank you for your help. I understand now what was my mistake. thanks for enlightening me.
as you can see at Label, I put fee='Courier Fee (RM)'. how can I add another line of coding that consist of detail about the fee? for example, I have 2 couriers, PosLaju, and GDex with a different fee, 2MYR, and 3MYR, respectively. and how to add that into a function like this? i want to make it become if my first order is using PosLaju, so for the function below, fee become 2MYR
net=after+fee;
@IdlanHnf Since this discussion is closed ("Solved"), if you have a follow-up question, it would be best to post it as a new discussion (including your question, your code, etc.). You'll get a lot more people viewing it then.
Look closely here:
IF total>=20 THEN after=total-dis; ELSE dis=total*0.05; IF total>=30 THEN dis=total*0.07; ELSE dis=total*0.00; after=total-dis; net=after+5;
So when you have Total>= 20 you calculate After twice with different values of dis. So, which one do you expect? Also the first time you use total-dis the value of dis is not set, so that After is missing as a result.
You also need to consider that every value >30 is also greater than 20. Perhaps sequence of calculation is not as you do manually. Computers don't know to stop unless you tell them to explicitly.
I suggest that every where you have a "dis =" to create a different variable: dis1 = <calculation>; dis2= <calculation> . Then look at the different values and see what is going on.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: