BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NonSleeper
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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.

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

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.

art297
Opal | Level 21

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;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 729 views
  • 1 like
  • 2 in conversation