I have two data sets. One is automatically generated with a time stamp every second. The other is field notes of the time where a load is observed to begin, thus establishing a control point. I want to assign all points after that control point its load number until the next control point.
can anyone suggest a simple way to do this?
in essence I need the following
seconds | control point | load number |
12566 | 0 | . |
12567 | 0 | . |
12568 | 0 | . |
12569 | 1 | 1 |
12570 | 0 | . |
12571 | 0 | . |
12572 | 0 | . |
12573 | 0 | . |
12574 | 0 | . |
12575 | 0 | . |
12576 | 0 | . |
12577 | 0 | . |
12578 | 0 | . |
12579 | 0 | . |
12580 | 0 | . |
12581 | 0 | . |
12582 | 1 | 2 |
12583 | 0 | . |
12584 | 0 | . |
12585 | 0 | . |
12586 | 0 | . |
12587 | 0 | . |
12588 | 0 | . |
to become this
seconds | control point | load number |
12566 | 0 | . |
12567 | 0 | . |
12568 | 0 | . |
12569 | 1 | 1 |
12570 | 0 | 1 |
12571 | 0 | 1 |
12572 | 0 | 1 |
12573 | 0 | 1 |
12574 | 0 | 1 |
12575 | 0 | 1 |
12576 | 0 | 1 |
12577 | 0 | 1 |
12578 | 0 | 1 |
12579 | 0 | 1 |
12580 | 0 | 1 |
12581 | 0 | 1 |
12582 | 1 | 2 |
12583 | 0 | 2 |
12584 | 0 | 2 |
12585 | 0 | 2 |
12586 | 0 | 2 |
12587 | 0 | 2 |
12588 | 0 | 2 |
Aha!
data b (drop=loadx);
set a;
retain loadx;
if not missing(load) then loadx = load;
load = loadx;
run;
maybe someone can explain what "(drop=loadx)" is doing
that is not my common usage of "retain" which I've always used to reorder columns.
retain control_point 0;
if load_number ne . then control_point=load_number;
And thank you for that as well... I'll try it.
Aha!
data b (drop=loadx);
set a;
retain loadx;
if not missing(load) then loadx = load;
load = loadx;
run;
maybe someone can explain what "(drop=loadx)" is doing
that is not my common usage of "retain" which I've always used to reorder columns.
drops it from the final data set.
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 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.