Help using Base SAS procedures

How to list specific observations

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

How to list specific observations

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?


Accepted Solutions
Solution
‎02-04-2012 06:01 PM
PROC Star
Posts: 7,474

How to list specific observations

Posted in reply to NonSleeper

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


All Replies
Solution
‎02-04-2012 06:01 PM
PROC Star
Posts: 7,474

How to list specific observations

Posted in reply to NonSleeper

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.

PROC Star
Posts: 7,474

How to list specific observations

Posted in reply to NonSleeper

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;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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