> The execution of the prxmatch function needs to happen in the data
> step, not in the macro. The current macro is working on the value X,
> not on the value of the variable named X.
So prxmatch() is one of those functions that can't be used in a macro
outside a datastep? Nice...
> Rewrite it. You don't need any %LETs or %SYSFUNCs at all.
Hehe -- thanks for the advice ;) I guess I will rewrite it completely,
to take a table name and work over the columns. I really need to do the
pattern matching to make the function do what I want, so if I can't do
that in a macro function (for whatever reason), then the macro function
approach won't work at all.
prxmatch() also crashes if it isn't wrapped in a sysfunc, as far as I
> You can use the IFN function in place of the %IF.
Sure, I will check it out.
Thanks for all your help.
> > Here is an abbreviated version of the macro ....
> > %MACRO WS_FHTYPE(CTXT);
> > %LET CTXT=%sysfunc(compress(&CTXT., , psc));
> > %LET CTXT=%sysfunc(upcase(&CTXT.));
> > %LET
> > )|(REMOVE)/;
> > %IF %sysfunc(prxmatch(&REWORKRE., &CTXT.)) %THEN %LET
> > HUTYPE=NOTHU;
> > %ELSE %LET HUTYPE=UNCLASS;
> > "&HUTYPE."
> > %MEND;
> > ... and some test code (yt should have "NOTHU"):
> > data barfoo;
> > x = 'iamacabin';
> > y = 'iamareworksfrslfdkjl';
> > xt = %WS_FHTYPE(x);
> > yt = %WS_FHTYPE(x);
> > run;
> > I imagine it is a problem with (un)quoting and sysfunc and prxmatch,
> > I am baffled and would appreciate any advice I can get...
> > Note that I am basically trying to approximate the following pattern
> > (from a SQL database -- PostgreSQL):
> > CREATE FUNCTION add_em(integer, integer) RETURNS integer AS $$
> > SELECT $1 + $2;
> > $$ LANGUAGE SQL;
> > SELECT add_em(1, 2) AS answer;
> > UPDATE foo set col1=add_em(col2, col3);
> >> =====
> >> 10 %macro ws_fhtype(parm1);
> >> 11 reverse(&PARM1.);
> >> 12 %mend ws_fhtype;
> >> 13
> >> 14 data whysodifficult;
> >> 15 stuff = 'iamacabin';
> >> 16 x = %WS_FHTYPE(stuff);
> >> 17 put x=;
> >> 18 run;
> >> x=nibacamai
> >> NOTE: The data set WORK.WHYSODIFFICULT has 1 observations and 2
> >> variables.
> >> NOTE: DATA statement used (Total process time):
> >> real time 0.16 seconds
> >> cpu time 0.00 seconds
> >> =====
> >> In that example, the macro returned a value based on the value of
> >> variable named as the parameter, which I think is what you want.
> >> On Mar 9, 2011, at 5:15 PM, Sprague, Webb (OFM) wrote:
> >>> I would like to use a macro function to process columns in a
> >> datastep, but the name of the variable, rather than its value, is
> >> getting passed to the macro function.
> >>> How do I "expand" the variable into its value?
> >>> Here is an example (sans macro definition of %WS_FHTYPE, since it
> >> long). I want the macro function to be passed the text
> >> not "stuff":
> >>> data whysodifficult;
> >>> stuff = 'iamacabin';
> >>> x = %WS_FHTYPE(stuff);
> >>> run;