Date: Wed, 12 Jan 2000 03:01:11 +0100
Reply-To: Fabrizio Carinci <carinci@CMNS.MNEGRI.IT>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Fabrizio Carinci <carinci@CMNS.MNEGRI.IT>
Subject: Re: Problems with data step.
In-Reply-To: <034452FA79E2D211A2DC0008C724EDA501FA3D8F@ntmsg0024.corpmail.telstra.com.au>
Content-Type: TEXT/PLAIN; charset=US-ASCII
Pete,
that means you will calculate profeta only when you meet the first record
of a new combination of those variables.
The by statement following a SET does create first.anything for you.
(quite a singular sintax for SAS, but there are many singularities in this
language).
However,
in the case of Angelo Menna, I apologise for a likely misunderstanding:
he was perhaps referring to a single combination per subject (i.e.
distinct values), which in case may be solved by something like:
data pippo;
input PATIENTC TRT1 TRT2 TRT3 TRT4;
cards;
131130 1 2 5 90
131698 90 . . .
131718 2 3 90 90
131762 2 4 90 90
131768 2 4 90 90
131771 90 . . .
131804 90 90 . .
131806 2 3 4 .
131923 1 90 90 .
131975 2 90 90 .
;
run;
data galeone (keep=profeta);
set pippo;
length profeta $200;
array trt[4] trt1-trt4;
do i=1 to 4;
repeat=0;
do j=(i+1) to 4;
if trt[i]=trt[j] then repeat=1;
end;
if i=1 and repeat=0 then profeta=trim(left(trt[i]));
else do;
if repeat=0 and trt[i]^=. then do;
if trim(left(profeta))^='' then do;
profeta=trim(left(profeta))||","||trim(left(trt[i]));
end;
else profeta=trim(left(trt[i]));
end;
end;
end;
run;
proc print;
run;
Again, this might be easily generalized to n variables...
Ciao
Fabrizio
On Wed, 12 Jan 2000, Lucas, Peter (Syd) wrote:
> Fabrizio,
>
> I'm new to SAS and am curious about the follow code
>
> if first.trt1 & first.trt2 & first.trt3 & first.trt4;
>
> Does this mean we will only calculate profeta if its the first record in
> each column ?
>
> Pete
>
> > -----Original Message-----
> > From: Fabrizio Carinci [SMTP:carinci@CMNS.MNEGRI.IT]
> > Sent: Wednesday, January 12, 2000 11:47 AM
> > To: SAS-L@AKH-WIEN.AC.AT
> > Subject: Re: Problems with data step.
> >
> > Dear Angelo,
> > please try to use the following:
> >
> > =======
> >
> > proc sort data=pippo;
> > by trt1 trt2 trt3 trt4;
> > run;
> >
> > data galeone (keep=profeta);
> > set pippo;
> > by trt1 trt2 trt3 trt4;
> > if first.trt1 & first.trt2 & first.trt3 & first.trt4;
> > profeta=trim(left(trt1))||","||trim(left(trt2))||","||trim(left(trt3))||",
> > "||trim(left(trt4));
> > run;
> >
> > proc print;run;
> >
> > ======
> >
> > You may easily generalize from that by using do loops, or use proc means
> > instead of proc freq, with the 'type' selection on.
> >
> > Hope this helps,
> > Ciao
> > Fabrizio
> >
> > On Wed, 12 Jan 2000, Angelo Menna wrote:
> >
> > > Dear All,
> > > please consider the following data:
> > >
> > > PATIENTC TRT1 TRT2 TRT3 TRT4
> > > 131130 1 2 5 90
> > > 131698 90
> > > 131718 2 3 90 90
> > > 131762 2 4 90 90
> > > 131768 2 4 90 90
> > > 131771 90
> > > 131804 90 90
> > > 131806 2 3 4
> > > 131923 1 90 90
> > > 131975 2 90 90
> > >
> > > I'd like to have a new var (TERAPIA) to obtain distinct values of
> > trt1-trt4
> > > separated by comma
> > > (e.g. for PATIENTC=131718 TERAPIA='2,3,90')
> > >
> > > I tried this code (but it does not work):
> > >
> > > data pluto ;
> > > length terapia temp1 $30 temp2 $2 ;
> > > set pippo ;
> > >
> > > array baudo trt1-trt4 ;
> > >
> > > do i=1 to 4;
> > > if i=1 then
> > > do;
> > > terapia=trt1 ;
> > > temp2=trt1 ;
> > > end;
> > > else
> > > do;
> > > if baudo(i) then
> > > do;
> > > if temp2^=baudo(i) then
> > > do;
> > > temp1=terapia||','||baudo(i) ;
> > > temp2=baudo(i) ;
> > > terapia=temp1;
> > > end;
> > > end;
> > > end;
> > > end;
> > > run;
> > >
> > >
> > > Any help is appreciated.
> > > TIA, Angelo.
> > >
> >
> > ==========================================================================
> > =====
> > Fabrizio Carinci, Statistician
> > Head, Unit of Statistics and Information Systems,
> > Department of Clinical Pharmacology and Epidemiology
> > Consorzio Mario Negri Sud, Strada Nazionale-66030 S.Maria Imbaro
> > (Chieti)-ITALY
> > Web: http://www.cmns.mnegri.it
> > --------------------------------------------------------------------------
> > -----
> > TEL: 39-0872-570265 FAX: 39-0872-578240
> > E-MAIL:carinci@cmns.mnegri.it
> > ==========================================================================
> > =====
>
==============================================================================
Fabrizio Carinci, Statistician
Head, Unit of Statistics and Information Systems,
Department of Clinical Pharmacology and Epidemiology
Consorzio Mario Negri Sud, Strada Nazionale-66030 S.Maria Imbaro (Chieti)-ITALY
Web: http://www.cmns.mnegri.it
-------------------------------------------------------------------------------
TEL: 39-0872-570265 FAX: 39-0872-578240 E-MAIL:carinci@cmns.mnegri.it
==============================================================================
|