Help using Base SAS procedures

Minusing first obs with another leaving first observation

Reply
Regular Contributor
Posts: 229

Minusing first obs with another leaving first observation

i have ao datasets i want to minus the first observation by another


data x;
input id sal;
cards;
1 2
3 4
5 6
7 8
run;



i want like this id -sal by leaving the first observariopn 1-4,3-6,5-8 finally the output shd be like this.
SAS Employee
Posts: 105

Re: Minusing first obs with another leaving first observation

You can use the lag function/
If i take your example it may look like this:

data b;
set x;
w=lag(id)-sal;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: Minusing first obs with another leaving first observation

A DATA step and investigate using the LAG function to use variable values from a previous observation. Have a look at the SAS.COM support website and the SAS Language Guide discussion on the LAG function. Also, there are also technical papers from prior conferences available on the website.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 2 replies
  • 115 views
  • 0 likes
  • 3 in conversation