I have to calculate the discount based on the purchased amount by the customer. For example if he has purchased for amount 1000 Rs, he should get 5% discount and if he bought for 2000 the discount should be 10% and if he has done for 3000 he should get 20% and above 3000 means he should get 30% discount.
So we have to calculate the amount in the new variable after the discount is applied .
cid purchased_amt
1 1000
2 2000
3 3000
4 4000
PROC FORMAT is well suited for this kind of classification problem. See if you can use this as a template
proc format;
invalue discount
0 -< 1000 = 0
1000 -< 2000 = 0.05
2000 -< 3000 = 0.2
3000 - high = 0.3;
run;
data have;
input cid amt;
datalines;
1 1000
2 2000
3 3000
4 4000
;
data want;
set have;
dicount=input(amt, discount.);
run;
PROC FORMAT is well suited for this kind of classification problem. See if you can use this as a template
proc format;
invalue discount
0 -< 1000 = 0
1000 -< 2000 = 0.05
2000 -< 3000 = 0.2
3000 - high = 0.3;
run;
data have;
input cid amt;
datalines;
1 1000
2 2000
3 3000
4 4000
;
data want;
set have;
dicount=input(amt, discount.);
run;
Hi @rohithverma ,
You can try this. Hope this help!
data have;
input cid amt;
cards;
1 1000
2 2000
3 3000
4 4000
;
run;
data want;
set have;
format discount percent.;
if 0 < amt <= 1000 then discount = 0;
else if 1000 < amt <= 2000 then discount = 0.05;
else if 2000 < amt <= 3000 then discount = 0.2;
else discount = 0.3;
new_amt = amt * (1-discount);
run;
Thank you very much..!
@rohithverma wrote:
Thank you very much..!
One of the very powerful advantages to @PeterClemmensen's approach is that if the rules change for this discounting procedure you only have to make the change in the proc format code where it would be easy to modify the discount range, the actual discount or both.
A solution that involves If/then/else coding requires modifying more code with associated increased possibilities of typos or missing an end point for a range.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.