I calculate the time duration variable between the end point and the first point. The variable has some negative values, which could be due to some mistake of data entry or so.
So I want to list the observations that have negative duration values, as well as end point and first point to see what happens. How can I do that?
Your question will be easier to answer given an example dataset. From the sound of your question, you want to identify all or some records for given ids that contain at least one negative duration value.
I would do that using a dow loop in a datastep in order to create a field that indicate on all of an id's records, that one or more of the duration values are negative.
Then, you could either use that indicator in a where statement in proc print to only print those ids that contain a negative value or, in a datastep (using first and last identifiers using id in a by statement) and only output the first, negative, and last values for those ids.
Your question will be easier to answer given an example dataset. From the sound of your question, you want to identify all or some records for given ids that contain at least one negative duration value.
I would do that using a dow loop in a datastep in order to create a field that indicate on all of an id's records, that one or more of the duration values are negative.
Then, you could either use that indicator in a where statement in proc print to only print those ids that contain a negative value or, in a datastep (using first and last identifiers using id in a by statement) and only output the first, negative, and last values for those ids.
btw: here is an example of how you might do it:
data have;
input id duration;
cards;
1 5
1 3
1 -1
1 4
1 5
2 3
2 1
2 3
2 4
3 1
3 2
3 3
3 -2
3 4
;
data want;
do until(last.id);
set have;
by id;
if duration lt 0 then wantit=1;
end;
do until(last.id);
set have;
by id;
if wantit and
(first.id or last.id or duration lt 0)
then output;
end;
run;
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.