Hello,
I have the following data set.
city Year D87 X dx
1 82 0 a -
2 87 1 b (b-a)
3 82 0 c -
4 87 1 d (d-c)
5 82 0 e -
6 87 1 f (f-e)
What procedure should be used to achieve dx ?
Thank You
In a data step:
pX = lag(X);
if D87 then dx = X - pX;
drop pX;
L_x = lag(x);
dx = x-L_x;
if d87 = 0 then dx = .;
Or you could use the DIF function, defined as X-lag(X):
dx=dif(x);
if d87=0 then dx=.;
Or slightly more economical.
dx= ifn(d87=1,dif(x),.) ;
Hello @Golf,
Glad to see that mkeintz's solution worked for you. Then it would be fair and help later readers if you marked his helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: Select his post as the solution after clicking "Not the Solution" in the option menu (see icon below) of the current solution.
Using the IFN() and DIF() functions, as suggested by @mkeintz, is the most economical way.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.