BookmarkSubscribeRSS Feed
Vince28_Statcan
Quartz | Level 8

Hi,

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.

Thanks,

Vincent

1 REPLY 1
snoopy369
Barite | Level 11

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

%macro scanplus(string=,wordpos=,wordcount=,delimeter=NA,modifiers=NA);

%if &delimeter=NA %then %do;

function1(&string,&wordpos,&wordcount);

%end;

%else do;

function2(&string,&wordpos,&wordcount,&delimeter,&modifiers);

%end;

%mend scanplus;

Suboptimal but not horrendous.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 923 views
  • 0 likes
  • 2 in conversation