From: Al on
Dear All:


This is the dataset i have ..



data have ;
input pat $ Dep $ rel $ out $ ds $ ;
cards;
123 CLI MIL RES AE
123 CLI MOD RES DS
345 DMA SEV NOT AE
345 DMA SEV RES DS

;
run;

Pat and Dep being the key variables , if the values for
variables(Rel,out) match per pat and per Dep , they must be set to
missing ,

below is the output that i am looking for ...


Pat Dep Rel out ds
123 CLI MIL AE
123 CLI MOD DS
345 DMA NOT AE
345 DMA RES DS

Thanks in Advance
Al
From: Arthur Tabachneck on
Al,

Your description doesn't match your desired output. However, if the
following is what you want and your data are already sorted by pat Dep
out, then the following code might do what you want:

data want (drop=gotone);
set have;
retain gotone;
by pat Dep out;
if first.out then do;
gotone=0;
if not last.out then do;
gotone=1;
call missing(out);
end;
end;
else if gotone then call missing(out);
run;

HTH,
Art
--------------
On Jun 22, 7:40 pm, Al <ali6...(a)gmail.com> wrote:
> Dear All:
>
> This is  the dataset i have ..
>
> data have ;
> input pat $ Dep $ rel $ out $ ds $ ;
> cards;
> 123 CLI MIL RES AE
> 123 CLI MOD RES DS
> 345 DMA SEV NOT AE
> 345 DMA SEV RES DS
>
> ;
> run;
>
> Pat and Dep being the key variables ,  if the values for
> variables(Rel,out) match per pat and per Dep , they must be set to
> missing ,
>
> below is the output that i am looking for ...
>
> Pat Dep  Rel    out   ds
> 123 CLI   MIL          AE
> 123 CLI   MOD        DS
> 345 DMA       NOT  AE
> 345 DMA       RES  DS
>
> Thanks in Advance
> Al

From: Al on
On Jun 22, 10:58 pm, Arthur Tabachneck <art...(a)netscape.net> wrote:
> Al,
>
> Your description doesn't match your desired output.  However, if the
> following is what you want and your data are already sorted by pat Dep
> out, then the following code might do what you want:
>
> data want (drop=gotone);
>   set have;
>   retain gotone;
>   by pat Dep out;
>   if first.out then do;
>     gotone=0;
>     if not last.out then do;
>       gotone=1;
>       call missing(out);
>     end;
>   end;
>   else if gotone then call missing(out);
> run;
>
> HTH,
> Art
> --------------
> On Jun 22, 7:40 pm, Al <ali6...(a)gmail.com> wrote:
>
>
>
> > Dear All:
>
> > This is  the dataset i have ..
>
> > data have ;
> > input pat $ Dep $ rel $ out $ ds $ ;
> > cards;
> > 123 CLI MIL RES AE
> > 123 CLI MOD RES DS
> > 345 DMA SEV NOT AE
> > 345 DMA SEV RES DS
>
> > ;
> > run;
>
> > Pat and Dep being the key variables ,  if the values for
> > variables(Rel,out) match per pat and per Dep , they must be set to
> > missing ,
>
> > below is the output that i am looking for ...
>
> > Pat Dep  Rel    out   ds
> > 123 CLI   MIL          AE
> > 123 CLI   MOD        DS
> > 345 DMA       NOT  AE
> > 345 DMA       RES  DS
>
> > Thanks in Advance
> > Al- Hide quoted text -
>
> - Show quoted text -

I apolozise if i dint explain the scenario right .. let me try one
more time .. for all the obserations with same pat ,dep values ..if
values rel and out fields are same they should be set to missing .. i
ran your code, the rel values for pat 345 are same but they were not
set to missing .



Thanks in advance
Al
From: Arthur Tabachneck on
Al,

You could probably do what you want with two passes through your
data. For example:

data have ;
input pat $ Dep $ rel $ out $ ds $ ;
cards;
123 CLI MIL RES AE
123 CLI MOD RES DS
345 DMA SEV NOT AE
345 DMA SEV RES DS
;

data want (drop=gotone);
set have;
retain gotone;
by pat Dep out notsorted;
if first.out then do;
gotone=0;
if not last.out then do;
gotone=1;
call missing(out);
end;
end;
else if gotone then call missing(out);
run;

data want (drop=gotone);
set want;
retain gotone;
by pat Dep rel notsorted;
if first.rel then do;
gotone=0;
if not last.rel then do;
gotone=1;
call missing(rel);
end;
end;
else if gotone then call missing(rel);
run;

HTH,
Art
--------------
On Jun 23, 12:43 am, Al <ali6...(a)gmail.com> wrote:
> On Jun 22, 10:58 pm, Arthur Tabachneck <art...(a)netscape.net> wrote:
>
>
>
>
>
> > Al,
>
> > Your description doesn't match your desired output.  However, if the
> > following is what you want and your data are already sorted by pat Dep
> > out, then the following code might do what you want:
>
> > data want (drop=gotone);
> >   set have;
> >   retain gotone;
> >   by pat Dep out;
> >   if first.out then do;
> >     gotone=0;
> >     if not last.out then do;
> >       gotone=1;
> >       call missing(out);
> >     end;
> >   end;
> >   else if gotone then call missing(out);
> > run;
>
> > HTH,
> > Art
> > --------------
> > On Jun 22, 7:40 pm, Al <ali6...(a)gmail.com> wrote:
>
> > > Dear All:
>
> > > This is  the dataset i have ..
>
> > > data have ;
> > > input pat $ Dep $ rel $ out $ ds $ ;
> > > cards;
> > > 123 CLI MIL RES AE
> > > 123 CLI MOD RES DS
> > > 345 DMA SEV NOT AE
> > > 345 DMA SEV RES DS
>
> > > ;
> > > run;
>
> > > Pat and Dep being the key variables ,  if the values for
> > > variables(Rel,out) match per pat and per Dep , they must be set to
> > > missing ,
>
> > > below is the output that i am looking for ...
>
> > > Pat Dep  Rel    out   ds
> > > 123 CLI   MIL          AE
> > > 123 CLI   MOD        DS
> > > 345 DMA       NOT  AE
> > > 345 DMA       RES  DS
>
> > > Thanks in Advance
> > > Al- Hide quoted text -
>
> > - Show quoted text -
>
> I apolozise if i dint explain the scenario right .. let me try one
> more time .. for all the obserations with same pat ,dep values ..if
> values rel and out fields are same they should be set to missing .. i
> ran your code, the rel values for pat 345 are same but they were not
> set to missing .
>
> Thanks in advance
> Al- Hide quoted text -
>
> - Show quoted text -

From: Sid on
Al, here is a two-step approach using PROC SQL.

data have ;
input pat $ dep $ rel $ out $ ds $ ;
cards;
123 CLI MIL RES AE
123 CLI MOD RES DS
345 DMA SEV NOT AE
345 DMA SEV RES DS
;
run;

/* Get the count of distinct "rel" and "out" values for each pat-dep
combination */
proc sql;
create table table1 as
select pat, dep, rel, out, ds, count(distinct rel) as c1,
count(distinct out) as c2
from have
group by pat, dep;
quit;

data table2 (drop = rel out c1 c2 rename = (rel2 = rel out2 = out));
set table1;
by pat dep;
if c1 ne 1 then rel2 = rel;
else rel2 = .;
if c2 ne 1 then out2 = out;
else out2 = .;
run;

Hope this is helpful.

Sid


On Jun 22, 6:40 pm, Al <ali6058(a)gmail.com> wrote:
> Dear All:
>
> This is  the dataset i have ..
>
> data have ;
> input pat $ Dep $ rel $ out $ ds $ ;
> cards;
> 123 CLI MIL RES AE
> 123 CLI MOD RES DS
> 345 DMA SEV NOT AE
> 345 DMA SEV RES DS
>
> ;
> run;
>
> Pat and Dep being the key variables ,  if the values for
> variables(Rel,out) match per pat and per Dep , they must be set to
> missing ,
>
> below is the output that i am looking for ...
>
> Pat Dep  Rel    out   ds
> 123 CLI   MIL          AE
> 123 CLI   MOD        DS
> 345 DMA       NOT  AE
> 345 DMA       RES  DS
>
> Thanks in Advance
> Al