I need to loop through a dataset (built-in, training SAS table with data) and do some calculations based on it. First off, I don't know how I could loop through values in range of columns of the table. Second, need to loop through all values in every observation and calculate difference between previous and following value. Here is the example of a table:
Auto Price1 Price2 Price3
Mazda 35.000 40.500 38.000
Audi 70.000 60.000 80.000
BMW 110.000 85.000 93.000
Let's say my table is named Prices in SAS. I tried below but I know it's totally wrong. I have no idea how to start:
data data.Prices;
set myDataset.Prices;
do price_prev = Price1;
do price_next = Price2;
end;
end;
result = price_next-price_prev;
run;
Desired output should be as follows:
Auto Diff1 Diff2 Diff3
Mazda 0 5.500 -2.500
Audi 0 -10.000 20.000
BMW 0 -25.000 8.000
I need do use some kind of a loop but don't know how. Important thing is that I can't use macros or some other complex synthax. Just loops.