10-25-2013 12:16 PM
I recall reading, when I did my first FCMP subroutine a few months ago of the poorly documented limitations of VARARGS for FCMP subroutines in that it is only viable if you ought to use the subroutine within a proc fcmp whereas I need to get the routine out in data steps.
First, I was wondering if anyone knew about a potential fix working with SAS 9.2. I would also appreciate to know if this was fixed with 9.3 or 9.4
My problem is fairly simple - for a larger name analysis project, I need to create a function hybrid between scan and substring that I can call in a single line for code readability and further reusability. I could probably do the VARARGS issue through making it a macro that parses a bunch of code but even though FCMP will likely result in a slight efficiency loss, it seems more logical to build a function. Anyway -
I want to do a simple FCMP subroutine, call it "scanplus" which would take the following form if it existed:
call scanplus(string, wordpos, wordcount, outsubstr, <, <delimiter(s)> <, <modifier(s) >>>);
think of delimiters as <charlist> of the scan routine, wordpos as count and wordcount, the number of words I want to substract.
I wish the last 2 parameters to be optional similar to scan routine so as to avoid having potential users beyond myself have to add an empty string parameter or something similar. I'm wondering if anyone knows a work around within FCMP or if I am really stuck with a macro function that will essentially parse the code.
Objective is simply to extract a substring starting from the wordpos word ending to wordpos+wordcount-1 word (inclusively) which takes painfully a couple lines to write in a series of scans/substrings and conditions not to go below 1 or beyond countw. The optional parameters would be passed to scan function from within the FCMP subroutine.
10-25-2013 12:59 PM
I think the problem with VARARGS is that it requires an explicity defined temporary array containing the variable arguments. Not terribly useful...
I think if it were me I'd make it a macro function that called two different functions based on the number of arguments passed to the macro, ie something like
%if &delimeter=NA %then %do;
Suboptimal but not horrendous.