I have a table with 3 columns as follows:
USERID Date SurveryScore
123 01/01/06 120
123 01/03/06 200
123 01/05/06 150
123 01/07/06 220
234 01/05/06 180
234 01/06/06 190
345 01/02/06 250
456 01/01/06 110
456 01/04/06 170
It's ordered by date for each User. For example, User 123 took 4 surveys on 4 days and had 4 scores. My questions is how to find out the difference between the scores for each user. I tried to solve the problem in Teradata SQL but I'm not familiar with procedures and I was told it's still gonna be hard since it's hard to tell the LOOP function how many loops to calculate the difference because each user has different number of surveys taken. Can anyone help me with it? I use Teradata SQL or SAS 9. So if you could help me in either environment, that'll be greatly appreciated. The ideal output would look like this:
USERID Date SurveryScore Diff
123 01/01/06 120 0
123 01/03/06 200 80
123 01/05/06 150 -50
123 01/07/06 220 70
234 01/05/06 180 0
234 01/06/06 190 10
345 01/02/06 250 0
456 01/01/06 110 0
456 01/04/06 170 60
Start Free Trial