LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext 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:         Tue, 4 Mar 2008 14:44:51 -0500
Reply-To:     Mike Rhoads <RHOADSM1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mike Rhoads <RHOADSM1@WESTAT.COM>
Subject:      Re: Question abount counting strings
Comments: To: Guylhem Aznar <sasllist@guylhem.net>
In-Reply-To:  <9cc82a4d0803041019v1a8ccddcj237c7b728a86d58d@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

Guylhem

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. You could then use PROC FREQ or some other reporting procedure to count the transitions.

DATA Transitions (KEEP = patient_id transition); LENGTH patient_id $ 6 states $ 12 transition $ 2; INPUT patient_id states; DO I = 1 TO LENGTH(states) - 1; transition = SUBSTR(states,I,2); OUTPUT; END; CARDS; 124883 NH 124884 NHD 124885 NH 124886 N 124890 NPH 124899 NHPHPD RUN;

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.

Mike Rhoads Westat RhoadsM1@Westat.com

-----Original Message----- From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of Guylhem Aznar Sent: Tuesday, March 04, 2008 1:19 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Question abount counting strings

Hello

I have a problem : after various data steps, I have a record of the list of states a patient has been in, ex:

patient_id states 124883 NH 124884 NHD 124885 NH 124886 N 124890 NPH

I would like to count the transition between the states - in perl I would simply count the possible strings (NH, NP, PH, HP, HD, PD...)

How could I easily do that with that ?

There's a trick : a patient can return to previous states, or alternate betweem states like NHPHPD (n=new, d=death) : here there should be 2 HP and 1 PH.

I have learn about the prx commands, but I have a hard time translating from my regexp logic to their logic.

Any help would be welcome.

Thanks Guylhem


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