BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MS_Egyptian
Fluorite | Level 6


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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

data want;

set have;

difference=dif(value);

run;

Message was edited by: Linlin

View solution in original post

4 REPLIES 4
Linlin
Lapis Lazuli | Level 10

data want;

set have;

difference=dif(value);

run;

Message was edited by: Linlin

mrtball
Obsidian | Level 7

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

mp254
Calcite | Level 5

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?

Ranny
Obsidian | Level 7

how to keep the first value as it is?

SAS Innovate 2025: Register Now

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!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 4 replies
  • 21759 views
  • 0 likes
  • 5 in conversation