when i use a DO loop, the LAG function works as follows.
================
data t;
do i=1 to 4;
j=lag(i);
output;
end;
====================
it gives
==========
i j
1 .
2 1
3 2
4 3
=========
however, the following does not.
===========
data t;
i=1;j=lag(i);
output;
i=2;j=lag(i);
output;
i=3;j=lag(i);
output;
i=4;j=lag(i);
output;
run;
=========
it gives
==========
i j
1 .
2 .
3 .
4 .
==========
any idea? thanks.
Each lag function creates its own queue so with 4 lag calls versus 1 lag function you will see different behaviour.
This is is a fairly contrived example, what are you actually trying to achieve, or is it for learning purposes.
If learning, read this paper : http://www.lexjansen.com/phuse/2011/cc/CC08.pdf
Each lag function creates its own queue so with 4 lag calls versus 1 lag function you will see different behaviour.
This is is a fairly contrived example, what are you actually trying to achieve, or is it for learning purposes.
If learning, read this paper : http://www.lexjansen.com/phuse/2011/cc/CC08.pdf
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.