Date: Thu, 26 Apr 2007 09:35:19 -0500
Reply-To: "Huang, JS" <Huang.JS@PRINCIPAL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Huang, JS" <Huang.JS@PRINCIPAL.COM>
Subject: Re: A COUNT PROBLEM
In-Reply-To: A<200704261418.l3QAkHse020138@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
Try this:
data Test;
length visit $ 10;
input subject visit &;
datalines;
001 screening
001 Week 1
001 Week 5
001 Week 5
001 Week 9
002 screening
002 Week 1
002 Week 6
002 Week 6
002 Week 10
;
data Result(drop=LastVisit);
retain visit1 LastVisit;
set Test;
if visit eq 'screening' then
do;
visit1=-1;
end;
else do;
if visit1 eq -1 then do;
visit1=1;
LastVisit=visit;
end;
else do;
if visit ne LastVisit then visit1=visit1+1;
LastVisit=visit;
end;
end;
run;
proc print;
var subject visit visit1;
run;
***** Output *****
The SAS System 06:47
Thursday, April 26, 2007 63
Obs subject visit visit1
1 1 screening -1
2 1 Week 1 1
3 1 Week 5 2
4 1 Week 5 2
5 1 Week 9 3
6 2 screening -1
7 2 Week 1 1
8 2 Week 6 2
9 2 Week 6 2
10 2 Week 10 3
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Rathindronath
Sent: Thursday, April 26, 2007 9:19 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: A COUNT PROBLEM
I have a following Dataset:
subject visit
------- -----
001 screening
001 Week 1
001 Week 5
001 Week 5
001 Week 9
002 screening
002 Week 1
002 Week 6
002 Week 6
002 Week 10
I need the following result with counts:
subject visit visit1
------- ----- ------
001 screening -1
001 Week 1 1
001 Week 5 2
001 Week 5 2
001 Week 9 3
002 screening -1
002 Week 1 1
002 Week 6 2
002 Week 6 2
002 Week 10 3
Thanks a lot.
-----Message Disclaimer-----
This e-mail message is intended only for the use of the individual or
entity to which it is addressed, and may contain information that is
privileged, confidential and exempt from disclosure under applicable law.
If you are not the intended recipient, any dissemination, distribution or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify us immediately by
reply email to Connect@principal.com and delete or destroy all copies of
the original message and attachments thereto. Email sent to or from the
Principal Financial Group or any of its member companies may be retained
as required by law or regulation.
Nothing in this message is intended to constitute an Electronic signature
for purposes of the Uniform Electronic Transactions Act (UETA) or the
Electronic Signatures in Global and National Commerce Act ("E-Sign")
unless a specific statement to the contrary is included in this message.
While this communication may be used to promote or market a transaction
or an idea that is discussed in the publication, it is intended to provide
general information about the subject matter covered and is provided with
the understanding that The Principal is not rendering legal, accounting,
or tax advice. It is not a marketed opinion and may not be used to avoid
penalties under the Internal Revenue Code. You should consult with
appropriate counsel or other advisors on all matters pertaining to legal,
tax, or accounting obligations and requirements.