Home > database >  [for] the first array of sas statement variable values and finally a numerical problem
[for] the first array of sas statement variable values and finally a numerical problem

Time:11-01

To ask everybody the teacher, now I have two columns of data, data format is as follows:
Id price
1 100
1 100
1 100
1 80
2 100
2 100
2 50
3 150
3 60
I want to by sas statements calculation under the same id, (the price of the first data) - (price) of the last data/(price of the first data)
For example when id=1, (100) - (80)/100
Want to ask everybody the teacher, how should express?

CodePudding user response:

Can someone help me have a look at it

CodePudding user response:

reference wave la-la-la reply 2 floor:
 create table # t (id int, price int) 
Insert into # t
1100 union all select
1100 union all select
1100 union all select
Select 1 reached union all
2100 union all select
2100 union all select
Select 2, 50 union all
3150 union all select
Select 3 '

; With cte as (
Select *, row_number () over (partition by id order by id) as an rn from # t
)

Select id, (min (price) - Max (price))/min (price) * 1.000 the as rate from cte
Group by id, price, rn
excuse me I the amount of data that may not so much how to do?

CodePudding user response:

I don't know if the original poster is to ask the price and minimum price, price difference
 
- if the first price is the maximum, the final price is the minimum
Select id, (Max - min (price)) (price) * 1.000/Max (price) ra from # t
Group by id

  • Related