LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2011, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 10 Mar 2011 10:07:57 -0800
Reply-To:   "Sprague, Webb (OFM)" <Webb.Sprague@OFM.WA.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Sprague, Webb (OFM)" <Webb.Sprague@OFM.WA.GOV>
Subject:   Re: "Unpacking" variable in a datastep into a "macro function"
Comments:   cc: "Mohrman, Mike (OFM)" <Mike.Mohrman@ofm.wa.gov>
In-Reply-To:   <35C2A042-21D4-498B-90EA-77431A058F90@alumni.stanford.org>
Content-Type:   text/plain; charset="us-ascii"

> 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 could tell.

> 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 > > > REWORKRE=/(RE*MO*DE*L)|(A*LTE*RA*T[IO]*N*)|(ADDI*T[IO]*)|(REHAB)|(REROO > F > > )|(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, > but > > 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 > the > >> 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 > is > >> long). I want the macro function to be passed the text "iamacabin", > >> not "stuff": > >>> > >>> data whysodifficult; > >>> stuff = 'iamacabin'; > >>> x = %WS_FHTYPE(stuff); > >>> run; > >>>


Back to: Top of message | Previous page | Main SAS-L page