Data A;
Imput id A;
Cards;
1 7
2 10
3 11
3 13
Run;
I want to create a variable B such
that
1 7 7-4=3
2 10 10-1=9
3 11 11-11=0(id=3)
3 13 13-11=2(id=3)
data want;
set A;
by id;
B=a-lag(a);
if first.id then B=0;
run;
Not as well known, but equally effective here, is a cousin of the LAG function. These two statements produce identical results:
B=a-lag(a);
B=dif(a);
Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.