Date: Wed, 5 Mar 2008 08:03:13 -0500
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: Question abount counting strings
I, too, probably don't understand what you are trying to do. Does the
following provide the result you are seeking to accomplish?
data want (drop=want: i j transitions);
input patient_id $ states $;
transitions='NH HD HP PH';
call missing (of want:);
do i=1 to length(states)-1;
do j=1 to 4;
if substr(states,i,2) eq scan(transitions,j) then want(j)+1;
On Wed, 5 Mar 2008 11:53:34 +0100, Guylhem Aznar <sasllist@GUYLHEM.NET>
>On 3/4/08, Mike Rhoads <RHOADSM1@westat.com> wrote:
>> So, a "state" is equivalent to a single letter, and a "transition" is
>> the combination of 2 adjacent states/letters, right?
>> If my understanding is correct, I wouldn't bother with regular
>> expressions. I would just use a DATA step with a DO-loop to create a
>> restructured data set with one record for each patient and transition.
>Sounds like a much better idea.
>I did a minor adaptation to your code, because I did end the
>transition (called "parcours in french" with a dot as a terminator
>/* parcours == transition */
>SET Work.Parcours (KEEP=patient_id parcours);
>DO I = 1 TO LENGTH(parcours) - 2;
> transition = SUBSTR(parcours,I,2);
>This gives something like
>patient_id parcours I transition
>80465 NHD 1 NH
>80465 NHD 2 HD
>However the result isn't exactly what I expected.
>Ideally, it would create for each patient a list of the transition
>found, ie of the 2 consecutive letters in the string, matched by a
>transition nh hd hp ph
>NHD 1 1 . .
>N . . . .
>NHPHD 1 1 1 1
>NHPHP 1 . 2 1
>I guess I would need a transpose somewhere. Yet I wonder how I will be
>able to count identical transition in the proc transpose (NHPHP
>example : 2 HP transitions)
>> Note that this does not create any records for patients like 124886,
>> have only one state and therefore no transitions. You could modify the
>> code to create a record for these patients if necessary.
>No - that's the right way to do. If they are in a continuous state,
>they have no transition.