Date: Fri, 9 Aug 1996 21:41:00 GMT
Reply-To: Richard Dickinson <R-Dickinson@TAMU.EDU>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Richard Dickinson <R-Dickinson@TAMU.EDU>
Organization: Texas A&M University
Subject: Followup question on string count
Several weeks ago I posed a datastep question on the list and
received many good responses to my problem. I've got a new one
now that is related to the original.
Take the following code (which helpful folks on the list
provided me):
%LET FINDSTR = "NEWVAR";
DATA A;
LENGTH CODE CCODE $ 60;
INPUT @1 CODE $CHAR60.;
CCODE=CODE;
COUNT=0;
I=INDEX(CCODE, &FINDSTR);
DO WHILE (I>0);
COUNT + 1;
CCODE=SUBSTR(CCODE, I+1);
I=INDEX(CCODE, &FINDSTR);
END;
KEEP CODE COUNT;
CARDS4;
IF NEWVAR=1 THEN NEWVAR=2;
IF NEWVAR=1 THEN
NEWVAR=2;
IF NEWVAR=1 THEN A=1; IF NEWVAR=2 THEN A=2;
;;;;
PROC PRINT;
RUN;
The above code will count the occurances of "NEWVAR" for each
line of input (2 for line 1, 1 for line 2, 1 for line 3, and 2
for line 4).
What I would rather the code do is count the
occurances of "NEWVAR" in a statement boundary (keep counting
"NEWVAR" until it hits a simicolon, at which time count gets
reset to zero). In other words, I want it to count the
occurances of "NEWVAR" until it hits a simicolon, even if it has
to go to a new line.
So for the above input lines, count would be:
2 for line 1, 1 for line 2, 2 for line 3, and 1 for line 4 (the
count for "NEWVAR" got reset because of the simicolon).
Any help would be appreciated.
Richard