I'm trying to create a user-define function that will work on character strings, so first I decided to learn the "plumbing" before developing the function. I've created two user defined functions: DAVECASE(simply returns the length of a character string) and DAVESUM(returns the sum of the two integers passed in). proc fcmp outlib=macros.userddefinedfunctions.davecase; ** path/name for user-defined function **;
function davecase(instring);
propstr = LENGTH(instring);
return(propstr);
endsub;
function davesum(part1,part2);
newsum = part1 + part2;
return(newsum);
endsub; Here is the code from which these two user-define functions are called: data x;
stringx = 'this is the untouched string';
daveway = DAVECASE(stringx); ** gets tripped up, seems to expect integer **;
oldway = PROPCASE(stringx); ** works fine **;
total = DAVESUM(2,3); ** works fine;
run; DAVESUM works perfectly, returning 5. DAVECASE seems to get tripped up because somewhere along the line an integer is expected instead of a character string. 27 data x;
28
29 stringx = 'this is the untouched string';
30
31 daveway = DAVECASE(stringx); ** gets tripped up, seems to expect integer **;
32
33 oldway = PROPCASE(stringx); ** works fine **;
34
35 total = DAVESUM(2,3); ** works fine;
36
37 run;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
31:22
NOTE: Invalid numeric data, stringx='this is the untouched string' , at line 31 column 22.
stringx=this is the untouched string daveway=1 oldway=This Is The Untouched String total=5 _ERROR_=1 _N_=1
NOTE: The data set WORK.X has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time): Is there something I need to do to indicate that the value being passed to DAVECASE is character? Thanks, ...dave
... View more