Hello everyone,
I'm not sure how best to phrase my question, so I'll just show the input and desired output:
The input has the first observation of each class marked with a 1 in the "Set" column. The sorting of the data is obviously very important here, as I've essentially binned the observations according to a particular behaviour that we were observing, which is marked by the 1. I want for all observations until the next instance of a 1 to be in the same class.
Set |
1 |
0 |
0 |
1 |
0 |
0 |
0 |
1 |
1 |
0 |
0 |
The desired output is as follows:
Set | Class |
1 | 1 |
0 | 1 |
0 | 1 |
1 | 2 |
0 | 2 |
0 | 2 |
0 | 2 |
1 | 3 |
1 | 4 |
0 | 4 |
0 | 4 |
Any help is much appreciated.
Cheers,
Sean
Something like this should get you started:
data want; set have; retain class 0; class=class+set; run;
RETAIN is the basic instruction to keep the value of a variable across interations in the data set.
Something like this should get you started:
data want; set have; retain class 0; class=class+set; run;
RETAIN is the basic instruction to keep the value of a variable across interations in the data set.
Then mark the useful response as a solution to your topic question.
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.
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.