BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cw_sas
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

 

 

View solution in original post

2 REPLIES 2
Reeza
Super User

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

 

 

cw_sas
Calcite | Level 5
many thanks.

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 Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 754 views
  • 0 likes
  • 2 in conversation