Hi,
any one knows how to get difference between two rows in DI. i.e. following is the orginal Table
Date | Value |
06/12/2013 | 150 |
07/12/2013 | 160 |
08/12/2013 | 180 |
09/12/2013 | 200 |
10/12/2013 | 250 |
and We need to generate a new column called Difference as the following table:
Date | Value | Difference |
06/12/2013 | 150 | |
07/12/2013 | 160 | 10 |
08/12/2013 | 180 | 20 |
09/12/2013 | 200 | 20 |
10/12/2013 | 250 | 50 |
data want;
set have;
difference=dif(value);
run;
Message was edited by: Linlin
data want;
set have;
difference=dif(value);
run;
Message was edited by: Linlin
Hello Linlin,
This solves my issue in terms of calculating differences across my dataset, however I dont want to run this for each record in the table everytime I insert a new row in the table - do you know if there is a function / piece of code which will basically calculate the difference between the last row and the new row being inserted and then insert the value? Also is this kind of difference calc only possible in Datastep?
Thanks,
Tom
Date | Value | Difference |
06/12/2013 | 250 | 50 |
07/12/2013 | 200 | 40 |
08/12/2013 | 160 | 30 |
09/12/2013 | 130 | 10 |
10/12/2013 | 120 | 0 |
How to get the difference output like this?
how to keep the first value as it is?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.