From: sas analysis on
Hi All,

I am having difficulty in figuring out how to filter observations in
sas. I need to look at observations while excluding others in the same
row...As such, I cannot delete the row...Is there any command for
filtering. I used to do this in spss. Here is an example of how the
dataset looks:

ID event1 event2 VARX event3
1 0 0 55 0
1 0 0 45 0
1 0 0 70 0
1 0 0 45 1
1 0 0 45 0
2 0 1 50 0
2 0 1 50 0
2 0 1 70 0
2 0 1 80 0
3 0 0 56 0
3 0 0 76 0
3 0 0 65 1
3 0 0 62 0

I want to filter any event=1 while keeping the other event. In this
case for ID2 I want to filter event2 and keep event1 because I want to
study event3 and if i were to delete ID2, I will lose all observations
from event1 and VARX.
Any ideas would be great...

Thank you!
From: Tom Abernathy on
On Mar 22, 10:51 pm, sas analysis <sasanaly...(a)gmail.com> wrote:
> Hi All,
>
> I am having difficulty in figuring out how to filter observations in
> sas. I need to look at observations while excluding others in the same
> row...As such, I cannot delete the row...Is there any command for
> filtering. I used to do this in spss. Here is an example of how the
> dataset looks:
>
> ID   event1     event2     VARX     event3
> 1       0             0            55          0
> 1       0             0            45          0
> 1       0             0            70          0
> 1       0             0            45          1
> 1       0             0            45          0
> 2       0             1            50          0
> 2       0             1            50          0
> 2       0             1            70          0
> 2       0             1            80          0
> 3       0             0            56          0
> 3       0             0            76          0
> 3       0             0            65          1
> 3       0             0            62          0
>
> I want to filter any event=1 while keeping the other event. In this
> case for ID2 I want to filter event2 and keep event1 because I want to
> study event3 and if i were to delete ID2, I will lose all observations
> from event1 and VARX.
> Any ideas would be great...
>
> Thank you!

Can you explain your data.
What do the variables event1,2, and 3 mean?
Why are their multiple records per ID?
What do you mean by filter other than the behaviour that you did not
want?
Are the events distinct? Could you code it as one variable with 4
levels (0,1,2,3)? and would that help?
From: Patrick on
I think you best give us an example how the resulting dataset after
applying the filter should look like.

Or you explain what kind of analysis you want to perform. May be one
of the SAS PROC's will do what you want without the need of pre-
processing the input data.
From: sas analysis on
On Mar 23, 7:01 am, Patrick <patrick.mat...(a)gmx.ch> wrote:
> I think you best give us an example how the resulting dataset after
> applying the filter should look like.
>
> Or you explain what kind of analysis you want to perform. May be one
> of the SAS PROC's will do what you want without the need of pre-
> processing the input data.

Thank you for your input. To answer Tom's question:
event3 is the outcome that I am looking at it. The reason I want to
filter observations if event1 or event2 occur is because they solve
the outcome if they happen. I can't delete rows since that will affect
all the independent variables I want to look at.

Patrick:
I want to use proc phreg since this is a longitudinal dataset.
This is an example of how the dataset may look: I just want to hide/
not include event2 for subject 2 since it occurred but keep all the
rest.

ID event1 event2 VARX event3
1 0 0 55 0
1 0 0 45 0
1 0 0 70 0
1 0 0 45 1
1 0 0 45 0
2 0 1(filter) 50 0
2 0 1(filter) 50 0
2 0 1(filter) 70 0
2 0 1(filter) 80 0
3 0 0 56 0
3 0 0 76 0
3 0 0 65 1
3 0 0 62 0

What proc will do this?

Thanks much!

From: Tom Abernathy on
I think that you might just want to truncate the data AFTER the first
event1 or event2. So you would not lose all the data for ID=2, just
the data after the first event1 or event2.
One way to do this might be like this:

data new;
truncate=0;
do until (last.id);
set old;
by id;
if not truncate then output;
if event1 or event2 then truncate=1;
end;
run;


On Mar 23, 1:06 pm, sas analysis <sasanaly...(a)gmail.com> wrote:
> On Mar 23, 7:01 am, Patrick <patrick.mat...(a)gmx.ch> wrote:
>
> > I think you best give us an example how the resulting dataset after
> > applying the filter should look like.
>
> > Or you explain what kind of analysis you want to perform. May be one
> > of the SAS PROC's will do what you want without the need of pre-
> > processing the input data.
>
> Thank you for your input. To answer Tom's question:
> event3 is the outcome that I am looking at it. The reason I want to
> filter observations if event1 or event2 occur is because they solve
> the outcome if they happen. I can't delete rows since that will affect
> all the independent variables I want to look at.
>
> Patrick:
> I want to use proc phreg since this is a longitudinal dataset.
> This is an example of how the dataset may look: I just want to hide/
> not include event2 for subject 2 since it occurred but keep all the
> rest.
>
> ID   event1     event2     VARX     event3
> 1       0             0            55          0
> 1       0             0            45          0
> 1       0             0            70          0
> 1       0             0            45          1
> 1       0             0            45          0
> 2       0             1(filter)    50          0
> 2       0             1(filter)    50          0
> 2       0             1(filter)    70          0
> 2       0             1(filter)    80          0
> 3       0             0            56          0
> 3       0             0            76          0
> 3       0             0            65          1
> 3       0             0            62          0
>
> What proc will do this?
>
> Thanks much!