BookmarkSubscribeRSS Feed
ramya_sahu
Obsidian | Level 7

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

6 REPLIES 6
Reeza
Super User

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


 

ramya_sahu
Obsidian | Level 7

Model

PriceMonth
15451
25151
33951
45851
55551
64651
74501
84551
96201
104651
16652
24402
35652
44052
54802
65052
74252
85452
94902
104802
15353
24603
34653
45953
55303
65703
75853
85403
95103
105103
15904
25204
35304
45254
55104
64604
75004
83504
94454
104554

 

please consider data

art297
Opal | Level 21

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

art297
Opal | Level 21

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

 

 

ramya_sahu
Obsidian | Level 7

HI, 

 

i need output like below or better you can suggest;

 

 Price Month wisePrice ChangePercentage change
Month1234 234234
model           
1500400350300 -100-50-50-20%-13%-14%
2           
3           
4           
5           
6           
7           
8           
9           
10           
Reeza
Super User

@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. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 6 replies
  • 1154 views
  • 2 likes
  • 3 in conversation