hello, i'm trying to create time-dependent variable, which means that the square of 'visiting number of each clinics' changes over time.
1) square of 'visiting number of each clinics means
ni is visiting number of 'i' clinic.
M is number of clinic.
and if i go to clinic 'a' and clinic 'b' in following sequence
a a a b b
... then total square is 9+4 = 13.
2) and i want make this 'total square' in time-dependent variable.
this is raw data.
id clinic
1 a
1 a
1 b
1 b
1 a
1 c
2 a
2 b
2 c
3 a
3 a
3 a
3 b
3 a
...and i want to create dataset like this.
id clinic totalsquare
1 a 1
1 a 4
1 b 5 *4+1*
1 b 8 *4+4*
1 a 13 *4+9*
1 c 14 *1+4+9*
2 a 1
2 b 2 *1+1*
2 c 3 *1+1+1*
3 a 1
3 a 4
3 a 9
3 b 10 *1+9*
3 a 17 *1+16*
thank you for your help.
This is an excellent homework assignment for understanding BY variables, and retaining values.
What have you tried so far?
This is an excellent homework assignment for understanding BY variables, and retaining values.
What have you tried so far?
1. in retain variable, i don't know how to replace retained value to another.
example
1 a 1
1 b 1+1
1 c 1+1+1
1 c 1+1+4
if i use retain variable by group, the last row become '1+1+1+4'(third '1' is retained from third row)
2. and when i use 'retain' by id and clinic, then i have to use 'proc sort' by id and clinic.
i want to make cumulative square sum in time order.
I'm not sure why you marked my comment as a solution for this topic. However, if you show even your code for reading in the original variables, without attempting the cumulative sum-of-squares, then you can have a start at getting help.
The variable to be "retained" is the cumulative sum of squares, which you (1) want to update with every incoming observation, and (2) you want to reset every time you begin a new id.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.