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 ?
Or you could use the DIF function, defined as X-lag(X):
if d87=0 then dx=.;
Or slightly more economical.
dx= ifn(d87=1,dif(x),.) ;
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.