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 (April 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 22 Apr 2004 20:25:59 -0400
Reply-To:     SAS Bigot <sas_bigot@ML1.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         SAS Bigot <sas_bigot@ML1.NET>
Subject:      Re: Searching backward through a file.
In-Reply-To:  <446DDE75CFC7E1438061462F85557B0F01DFA647@remail2.westat.com>
Content-Type: text/plain; charset="US-ASCII"

You need to be careful, especially in macros.

----- Original message ----- From: "Ed Heaton" <EdHeaton@WESTAT.COM> To: SAS-L@LISTSERV.UGA.EDU Date: Thu, 22 Apr 2004 12:57:03 -0400 Subject: Re: Searching backward through a file.

Paul,

Eureka! You have hit on the technique. Thanks a million. (Of course it's not foolproof.) I will post my code when I get it developed. I have a meeting to attend right now.

Ed

-----Original Message----- From: Choate, Paul@DDS [mailto:pchoate@DDS.CA.GOV] Sent: Thursday, April 22, 2004 12:47 PM To: Ed Heaton; SAS-L@LISTSERV.UGA.EDU Subject: RE: Searching backward through a file.

This is off your question Ed, but why not count parentheses between ";" delimiters and keep the line numbers of the ";" and the prior ";" that bracket the unbalanced count?

Paul Choate DDS Data Extraction (916) 654-2160

-----Original Message----- From: Ed Heaton [mailto:EdHeaton@WESTAT.COM <mailto:EdHeaton@WESTAT.COM> ] Sent: Thursday, April 22, 2004 8:41 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Searching backward through a file.

Good morning, all;

I am trying to create a little job to search SAS code for unbalanced parentheses. The following will alert me if I have an extra right parenthesis.

Data _null_ ; InFile sasCode end=eof ; Input ; If not missing(_inFile_) then do i=1 to length(_inFile_) ; Select ( rank( subStr( _inFile_ , i , 1 ) ) ) ; When (40) leftParen + 1 ; When (41) rightParen + 1 ; Otherwise ; End ; If ( leftParen lt rightParen ) then put _all_ ; End ; If eof then call symPut( "n" , put( _n_ , best. ) ) ; Run ;

Now I want to search for an extra left parenthesis. I envision starting at the bottom of the file and searching backward. Something like...

Data _null_ ; Retain N &n ; InFile sasCode ; /* Go to the bottom of the file. */ Input #N ; N + -1 ; If not missing(_inFile_) then do i=length(_inFile_) to 1 by -1 ; Select ( rank( subStr( _inFile_ , i , 1 ) ) ) ; When (40) leftParen + 1 ; When (41) rightParen + 1 ; Otherwise ; End ; If ( leftParen gt rightParen ) then put _all_ ; End ; If ( _n_ eq &n ) then stop ; Run ;

Of course, this doesn't work. Is there a way to make SAS read backward through a file. My other option is to write each line from the first read into a data set, reverse the order of the data set, and use it in the second

DATA step. This seems very clunky to me. Any suggestions?

Ed

Edward Heaton, SAS Senior Systems Analyst, Westat (An Employee-Owned Research Corporation), 1600 Research Boulevard, RW-3541, Rockville, MD 20850-3195 Voice: (301) 610-4818 Fax: (301) 610-5128 mailto:EdHeaton@Westat.com <mailto:EdHeaton@Westat.com> http://www.Westat.com <http://www.Westat.com>

-- http://www.fastmail.fm - Choose from over 50 domains or use your own


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