Hi all.
I'm having a problem with a recursive subroutine in proc FCMP, which I'm using as an example in some training I'm doing.
It is designed to get rid of multiple commas in a string. The function works fine for me if I copy it into standard data step code, but returns 'gobbldygook' characters when using FCMP and recursion.
The following code illustrates: Dataset A comes back with the following value in variable teststring: " dÐdÐ,Dave,James,Bob". I've tried variations on the code, and the first 5 characters always come out as random special characters.
Dataset B comes back with the correct string: "John,Jim,Dave,James,Bob"
I'd really appreciate any help in understanding why it's not working properly.
Thanks very much,
Robin
options cmplib=work.myfuncs;
proc fcmp outlib = work.myfuncs.mylib;
subroutine decomma(mystring $);
outargs mystring;
mystring = tranwrd(mystring,",,",",");
a = index(mystring,",,");
if a > 0 then call decomma(mystring);
endsub;
run;
data a;
teststring = "John,,,Jim,,Dave,,,James,Bob";
call decomma(teststring);
run;
data b;
mystring = "John,,,Jim,,Dave,,,James,Bob";
mystring = tranwrd(mystring,",,",",");
mystring = tranwrd(mystring,",,",",");
mystring = tranwrd(mystring,",,",",");
mystring = tranwrd(mystring,",,",",");
mystring = tranwrd(mystring,",,",",");
mystring = tranwrd(mystring,",,",",");
run;
Tested your programm using SAS 9.2 M3 and 9.3 M2. It seems to be a bug in 9.2, code works without any problem in 9.3.
Tested your programm using SAS 9.2 M3 and 9.3 M2. It seems to be a bug in 9.2, code works without any problem in 9.3.
Thank you very much for the testing. So it appears that from a SAS code point of view, there isn't actually a mistake, and it's a bug?
Do you need recursion?
Thanks very much for the responses. You're right that recursion is not needed here - it's an example I'm using in a training exercise to demonstrate the principle of recursion, and the fact it's possible to use it in SAS. Unfortunately, since it's buggy in my version of SAS, it appears that it's not a very example!
Can you make it work with two arguments to your call routine. Where in and out are different variables. That might "fix" the problem.
I'll try that when I'm back at work next week. I've now been able to test on a different v9.2 system with no problems, and it seems to be a bug with the specific version of SAS I'm using. Thanks again for replies.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.