BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi everyone!!

I'm a spanish student, and I need to scan a table in SAS, register by register, to make an update on every row (depending of several conditions that include variables in previous row)

For example, I want to modify the field Date2 in this example with de field Date of the previous field, if the previous row is the same ID:

Initially:

ID DATE DATE2
1 "25-Oct-2000" ""
1 "30-Oct-2001" ""
1 "25-Nov-2002" ""
2 "13-Jan-2000" ""
2 "15-Mar-2001" ""

Finally

ID DATE DATE2
1 "25-Oct-2000" ""
1 "30-Oct-2001" "25-Oct-2000"
1 "25-Nov-2002" "30-Oct-2001"
2 "13-Jan-2000" ""
2 "15-Mar-2001" "13-Jan-2000"

Thanks and sorry for my english (is very poor)!!!!!
3 REPLIES 3
deleted_user
Not applicable
Hi, not sure how to do it in Proc SQL, but in base SAS it can be done this way:

Data ;
Set ;
By Id;
DATE2=lag(DATE);
If first.ID then DATE2="";
Run;
deleted_user
Not applicable
Thanks!!

One doubt more: with your code, the last row in the final table is deleted. do you know why?
deleted_user
Not applicable
Fixed!!!

Other question. How can I define and work with a variable into a data segment?

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