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

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!

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
  • 761 views
  • 0 likes
  • 1 in conversation