Hello
Is there a way to create z1 with the value from x1 for a start, and then z2 with the value from z1, and z3 with the value from z2, but every time y changes z must again pick its value from x.
The problem is, that there are too many values in x, and I only need the first value from x every time y changes.
Data are sorted by column y.
In Excel it would be like this:
in cell z1: =x1
in cell z2: =if(y2=y1;z1;x2)
in cell z3: =if(y3=y2;z2;x3)
in cell z4: =if(y4=y3;z3;x4)
etc.
Data are big and I use SAS Enterprise Guide 7.11
For example:
Have: | |||
| x | y | z |
1 | 788 | 7 |
|
2 | 415 | 7 |
|
3 | 964 | 8 |
|
4 | 375 | 8 |
|
5 | 105 | 8 |
|
6 | 105 | 8 |
|
7 | 105 | 8 |
|
8 | 105 | 9 |
|
9 | 105 | 9 |
|
Want: | |||
| x | y | z |
1 | 788 | 7 | 788 |
2 | 415 | 7 | 788 |
3 | 964 | 8 | 964 |
4 | 375 | 8 | 964 |
5 | 105 | 8 | 964 |
6 | 105 | 8 | 964 |
7 | 105 | 8 | 964 |
8 | 105 | 9 | 105 |
9 | 105 | 9 | 105 |
Thank you 🙂
Yes, you can easily use BY group processing here. If you can't sort your data for some reason, you can use the NOTSORTED option.
data want; set have; by Y NOTSORTED; retain z; if first.y then z = x; run;
@martino1 wrote:
Hello
Is there a way to create z1 with the value from x1 for a start, and then z2 with the value from z1, and z3 with the value from z2, but every time y changes z must again pick its value from x.
The problem is, that there are too many values in x, and I only need the first value from x every time y changes.
Data are sorted by column y.
In Excel it would be like this:
in cell z1: =x1
in cell z2: =if(y2=y1;z1;x2)
in cell z3: =if(y3=y2;z2;x3)
in cell z4: =if(y4=y3;z3;x4)
etc.
Data are big and I use SAS Enterprise Guide 7.11
For example:
Have:
x
y
z
1
788
7
2
415
7
3
964
8
4
375
8
5
105
8
6
105
8
7
105
8
8
105
9
9
105
9
Want:
x
y
z
1
788
7
788
2
415
7
788
3
964
8
964
4
375
8
964
5
105
8
964
6
105
8
964
7
105
8
964
8
105
9
105
9
105
9
105
Thank you 🙂
Yes, you can easily use BY group processing here. If you can't sort your data for some reason, you can use the NOTSORTED option.
data want; set have; by Y NOTSORTED; retain z; if first.y then z = x; run;
@martino1 wrote:
Hello
Is there a way to create z1 with the value from x1 for a start, and then z2 with the value from z1, and z3 with the value from z2, but every time y changes z must again pick its value from x.
The problem is, that there are too many values in x, and I only need the first value from x every time y changes.
Data are sorted by column y.
In Excel it would be like this:
in cell z1: =x1
in cell z2: =if(y2=y1;z1;x2)
in cell z3: =if(y3=y2;z2;x3)
in cell z4: =if(y4=y3;z3;x4)
etc.
Data are big and I use SAS Enterprise Guide 7.11
For example:
Have:
x
y
z
1
788
7
2
415
7
3
964
8
4
375
8
5
105
8
6
105
8
7
105
8
8
105
9
9
105
9
Want:
x
y
z
1
788
7
788
2
415
7
788
3
964
8
964
4
375
8
964
5
105
8
964
6
105
8
964
7
105
8
964
8
105
9
105
9
105
9
105
Thank you 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.