Date: Tue, 11 Sep 2007 02:45:00 -0400
Reply-To: Jim Groeneveld <jim4stat@YAHOO.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <jim4stat@YAHOO.CO.UK>
Subject: Re: Constructing Variables
Hi Randy,
WHAT SHOULD THE CRITERION BE TO ADD VARC?
You omitted to indicate the criterion.
Now we just have to guess.
Furthermore, what is your overall problem?
Maybe you don't need such a (partial) solution at all,
but quite another overall solution.
Please tell us the purpose of this problem.
Finally, I guessed about the criterion
and developed a solution that fits your test data.
But it may not fit your real data at all!
DATA OldData;
INPUT VarA $CHAR1. Time : TIME8. @25 VarB $CHAR1.;
FORMAT Time TIME8.;
CARDS;
A 11:55:04
A 11:55:04
A 11:55:05
A 11:55:06
A 11:55:06
B 11:55:06 X
A 11:55:07
A 11:55:08
B 11:55:09 Y
;
RUN;
PROC PRINT DATA=OldData; RUN;
* Create Group variable;
DATA GrpData;
SET OldData;
BY VarA NOTSORTED;
* RETAIN Group 1; * not necessary because of sum statement below;
IF (VarA EQ 'A' AND FIRST.VarA) THEN Group + 1;
RUN;
PROC PRINT DATA=GrpData; RUN;
DATA NewData (DROP=Group);
MERGE GrpData /* with itself */
GrpData (RENAME=(VarB=VarC) WHERE=(VarC NE '') DROP=VarA Time);
BY Group;
IF (VarA EQ 'B') THEN VarC = '';
RUN;
PROC PRINT DATA=NewData; RUN;
Of course there are other coding solutions possible.
If you want more explanation on this code then please ask us.
Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
home.hccnet.nl/jim.groeneveld
On Mon, 10 Sep 2007 23:24:39 -0400, Randy <randistan69@HOTMAIL.COM> wrote:
>Dear Sas Users Group:
>
>My data set is as follows:
>
>VarA Time VarB
>A 11:55:04
>A 11:55:04
>A 11:55:05
>A 11:55:06
>A 11:55:06
>B 11:55:06 X
>A 11:55:07
>A 11:55:08
>B 11:55:09 Y
>and so on.
>The data set I want is to construct another VarC and
>
>VarA Time VarB VarC
>A 11:55:04 X
>A 11:55:04 X
>A 11:55:05 X
>A 11:55:06 X
>A 11:55:06 X
>B 11:55:06 X
>A 11:55:07 Y
>A 11:55:08 Y
>B 11:55:09 Y
>
>any suggestions?
>
> Randy