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 (September 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 28 Sep 2004 14:19:53 -0500
Reply-To:   "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Subject:   Re: errors by function SUBSTR
Comments:   To: Tony Wang <tonywolf@YAHOO.COM>
Content-Type:   text/plain; charset="us-ascii"

Tony,

What you are asking for is good old defensive programming. If one does not care to have some value in each value for variable 'a' but would like to know when a word does not meet the specifications, then you could do the following.

data sub ; set one ; length a $12. ;

if length(word) >= 12 then do ; a = substr(word,3,12) ; end;

else put word = ' is either blank or not long enough for the substr' ;

run ;

HTH Toby Dunn -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Tony Wang Sent: Tuesday, September 28, 2004 1:52 PM To: SAS-L@LISTSERV.UGA.EDU Subject: errors by function SUBSTR

Hi All,

When I use the function substr(var,num1,num2), there would be some errors in the sas log if var=' ' (missing) or num2 is out of the length of var.

eg,

data sub; a=substr('wellpoint',3,12); b=substr(' ',3,12); run;

In most of the cases it doesn't affect the results but I hate to see errors in the log. Is there an alternative way to do this?

Thanks

Tony


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