BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi all,

I want to make a training curve. Therefore I must add the previous Observation to my variable "X".
OBServation1: X= Condition from OBS1
OBServation2: X= x from OBS1 plus Condition from OBS2
OBServation3: X= x from OBS2 plus Condition from OBS3
OBServation4: X= x from OBS3 plus Condition from OBS4
OBServation5: X= x from OBS4 plus Condition from OBS5
OBServation6: X= x from OBS5 plus Condition from OBS6

But I dont know how I get the previous Observation. Maybe have anybody an idea?

Obs Condition X
1 0 0
2 1 1
3 1 2
4 0 2
5 0 2
6 1 3

Thanks, Lex
3 REPLIES 3
GertNissen
Barite | Level 11
data input;
input obs value;
datalines;
1 0
2 1
3 1
4 0
5 0
6 1
;
run;

data x;
set input;
retain x1;
x1 + value;
run;

Or you could experiment with the LAG function - http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000212547.htm
DanielSantos
Barite | Level 11
If I got this right, you should RETAIN variable X.

Retain, holds the value of the previous iteration.

Assuming that table1 holds the input data.

data table2;
set table1;
retain X 0; /* explicit retain for the X variable */
X=X+Condition;
run;

or simply:

data table2;
set table1;
X+Condition; /* implicit retain for the X variable, when using RETAIN_VAR+ */
run;

Both are the same.
On the latest, there's no need to explicitly use the retain statement.

Greetings from Portugal.

Daniel Santos at www.cgd.pt
deleted_user
Not applicable
Thanks. This is what Im looking for.

Greetings

Lex

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1081 views
  • 0 likes
  • 3 in conversation