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 (December 2002, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 11 Dec 2002 16:08:47 -0500
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: scan function question
Comments: To: "Primak, Philip" <Philip.Primak@GENZYME.COM>
Content-Type: text/plain; charset="iso-8859-1"


Think historical INPUT. In list input SAS skips over any number of spaces between fields. For example:

data _null_ ; input x ; put x= ; cards ; 1 1 1 1 ;

will find all numbers 1 for the first field. Well SCAN is constructed to do the same thing. What one needs is an optional parameter to tell SCAN whether to work this way or the way you would like. There may be something in Version 9 although it is probably a new function rather than an extra argument.

Be thankful you don't have to parse ---1-2-3-4--5 the way you indicated. in that case you would essentially have to write the scan function.

-----Original Message----- From: Primak, Philip [mailto:Philip.Primak@GENZYME.COM] Sent: Wednesday, December 11, 2002 10:56 AM To: SAS-L@LISTSERV.UGA.EDU Subject: scan function question

Hi SAS users,

I have to select the first word of the string using dash as delimiter. As you can see from the LOG below, it does not work correctly when the string starts from dash. In that case it chooses the 2nd word instead of the 1st one. Is there a way to fix it? The only idea that has come to my head so far is use trick like word1=scan(' '||str,1,'-') (Alternative way like check the 1st character using substr function I have rejected - it is not elegant and too strait forward). Any better ideas? Also, WHY scan function is not working correctly?

Advance thanks Philip Primak Genzyme

244 data _null_; 245 length word1 $8; 246 length str $16; 247 248 str='1-5678'; 249 word1=scan(str,1,'-'); 250 put 'Entire String: ' str/ 'The First Word: ' word1; 251 252 str='-5678'; 253 word1=scan(str,1,'-'); 254 put 'Entire String: ' str/ 'The First Word: ' word1; 255 256 run;

Entire String: 1-5678 The First Word: 1 Entire String: -5678 The First Word: 5678 NOTE: DATA statement used: real time 0.00 seconds cpu time 0.00 seconds

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