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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 21346 views
  • 0 likes
  • 5 in conversation