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

Hello,

I would like to create a lag variable for D based on qtr and mgrno. Obviously LAG doesn't work here because it doesn't recognize different mgrno.

Any ideas on this?

Many thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Sort the data in the right order then LAG() function will work.

data want ;

  set have ;

  by mgrno ticker qtr ;

lagd=lag(d);

if first.ticker then lagd=.;

run;

View solution in original post

4 REPLIES 4
Anotherdream
Quartz | Level 8

If you can, give an example of what you actually want with you data as an output.  I am not worrking what you mean by lag of qrt and mgrno, and your statement about lag.

Example, your qtr of 1980-4 has the mgrno 260 40 times. Do you want the D field lagged by 1 onto each of the 260 fields (so row 1 gets lagged into row 2). Or did you want the data structured as is to be lagged, regardless of the order or MGRNO?

Costasg
Calcite | Level 5

What I would like to do is to have the Lag Value of D for each mgrno for each stock separately.

Each stock has many investors. I want the lagged value for the particular investor.

So for example

1981-1  520 AA should have the value of 1980-4 520 AA

1981-1  835 AA should have the value of 1980-4 835 AA.

I hope you can understand what I mean.

Many thanks.

Tom
Super User Tom
Super User

Sort the data in the right order then LAG() function will work.

data want ;

  set have ;

  by mgrno ticker qtr ;

lagd=lag(d);

if first.ticker then lagd=.;

run;

Costasg
Calcite | Level 5

Many thanks Tom!

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 753 views
  • 0 likes
  • 3 in conversation