|
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
|