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-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
  • 843 views
  • 0 likes
  • 3 in conversation