HI,
I am stuck while analysing a data set.
i have prices of some models over 4 months.
I need a output where i can see the price change & % change in price month wise and overall for each model.
PFA sample data & suggest.
your suggestion will be highly appreciated.
Thanks
Please post the data into the question directly rather than as an attachment.
@ramya_sahu wrote:
HI,
I am stuck while analysing a data set.
i have prices of some models over 4 months.
I need a output where i can see the price change & % change in price month wise and overall for each model.
PFA sample data & suggest.
your suggestion will be highly appreciated.
Thanks
Model | Price | Month |
1 | 545 | 1 |
2 | 515 | 1 |
3 | 395 | 1 |
4 | 585 | 1 |
5 | 555 | 1 |
6 | 465 | 1 |
7 | 450 | 1 |
8 | 455 | 1 |
9 | 620 | 1 |
10 | 465 | 1 |
1 | 665 | 2 |
2 | 440 | 2 |
3 | 565 | 2 |
4 | 405 | 2 |
5 | 480 | 2 |
6 | 505 | 2 |
7 | 425 | 2 |
8 | 545 | 2 |
9 | 490 | 2 |
10 | 480 | 2 |
1 | 535 | 3 |
2 | 460 | 3 |
3 | 465 | 3 |
4 | 595 | 3 |
5 | 530 | 3 |
6 | 570 | 3 |
7 | 585 | 3 |
8 | 540 | 3 |
9 | 510 | 3 |
10 | 510 | 3 |
1 | 590 | 4 |
2 | 520 | 4 |
3 | 530 | 4 |
4 | 525 | 4 |
5 | 510 | 4 |
6 | 460 | 4 |
7 | 500 | 4 |
8 | 350 | 4 |
9 | 445 | 4 |
10 | 455 | 4 |
please consider data
If you want the output file in the structure you showed, use the same code as I suggested earlier, but transform the results. e.g.
proc sort data=have out=need; by model month; run; data need; set need; by model; change=ifn(first.model,.,price/lag(price)-1); run; proc transpose data=need prefix=Price_Month_ out=want (drop=_n:); by model; id month; var price; run; proc transpose data=need prefix=Change_Month out=need (drop=_:) ; by model; id month; var change; run; data want; merge want need; by model; format Change_Month1-Change_Month4 percent6.2;
run;
Art, CEO, AnalystFinder.com
I think that the following will do what you want:
proc sort data=have out=want; by model month; run; data want; set want; by model; change=ifn(first.model,.,price/lag(price)-1); run;
Art, CEO, AnalystFinder.com
HI,
i need output like below or better you can suggest;
Price Month wise | Price Change | Percentage change | |||||||||
Month | 1 | 2 | 3 | 4 | 2 | 3 | 4 | 2 | 3 | 4 | |
model | |||||||||||
1 | 500 | 400 | 350 | 300 | -100 | -50 | -50 | -20% | -13% | -14% | |
2 | |||||||||||
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 |
@ramya_sahu wrote:
HI,
i need output like below or better you can suggest;
Price Month wise Price Change Percentage change Month 1 2 3 4 2 3 4 2 3 4 model 1 500 400 350 300 -100 -50 -50 -20% -13% -14% 2 3 4 5 6 7 8 9 10
Are the values in that table made up or should they align somehow with your data posted?
Please make sure they line up, it really helps when trying to determine your logic.
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 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.