LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (March 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: Guylhem Aznar <sasllist@GUYLHEM.NET>

Guylhem,

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); array want(4); 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; end; end; nh=want(1); hd=want(2); hp=want(3); ph=want(4); datalines; 124883 NHD 124884 N 124885 NHPHD 124886 NHPHP ;

Art --------- On Wed, 5 Mar 2008 11:53:34 +0100, Guylhem Aznar <sasllist@GUYLHEM.NET> wrote:

>Hello > >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? > >True. > >> 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 >char. > >DATA Transitions; >/* parcours == transition */ >SET Work.Parcours (KEEP=patient_id parcours); > >DO I = 1 TO LENGTH(parcours) - 2; > transition = SUBSTR(parcours,I,2); > OUTPUT; >END; >RUN; > >This gives something like > >patient_id parcours >80465 NHD > >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 >count: > >transition >NHD >N >NHPHD > >should give > >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, who >> 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. > >Guylhem


Back to: Top of message | Previous page | Main SAS-L page