LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (July 1997, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 31 Jul 1997 19:55:09 -0400
Reply-To:     Anthony Ayiomamitis <ayiomamitis@IBM.NET>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Anthony Ayiomamitis <ayiomamitis@IBM.NET>
Subject:      Re: macro question (easy I hope)
Content-Type: text/plain; charset=us-ascii

Hi Robert,

The first line of the original question asked whether its possible for a MACRO to RETURN a VALUE which obviously is not possible as the user is suggesting an ability for us to write macro FUNCTIONS. I believe the original posting is attached below ...

Anthony.

Rose, Robert wrote: > > Maybe I've missed something (and I haven't been following the thread), > but you application looks like a perfect place to you a PUT function > statement, having earlier created your own INVALUE format. I do this > all the time. > > For example: > > (This code is in an INCLUDE that follows a PROC FORMAT statement, along > with several other INVALUE statements) > > /* Recode Raw PSU Input Value in 1985 Data to Get Stratum Value. */ > > INVALUE $Sta85_ /* Raw_PSU Stratum */ > '301' = '001' > '302' = '002' > '303' = '003' > '304' = '004' > '305' = '005' > '306' = '006' > '307' = '007' > '308' = '008' > '309' = '009' > '310' = '010' > '311' = '011' > '312' = '012' > '313' = '013' > '314' = '014' > '315' = '015' > '316' = '016' > '317' - '318' = '118' > '319' - '320' = '119' > '321' - '322' = '120' > '323' - '324' = '121' > '325' - '326' = '123' > '327', '331' = '125' > '328', '330' = '124' > '329', '332' = '126' > '333' - '335' = '127' > '336', '348' = '132' > '337', '346' = '135' > '338', '343' = '136' > '339', '344' = '137' > '340', '341' = '131' > '342', '350' = '133' > '349', '351' = '134' > '345', '347' = '138' > '352' = '017' > '354', '360' = '146' > '355', '357' = '145' > '353', '356' = '144' > '358', '359', '361' = '147' > '362' - '364' = '122' > '365', '367' , '371' = '130' > '366', '370' = '128' > '368' - '369' = '129' > '372' - '373' = '139' > '374', '376' = '140' > '375', '377' = '143' > '378' - '379' = '142' > '380' - '381' = '141' > '382' - '384' = '148' > Other = _ERROR_ ; > > (Pardon the alignment; it gets screwed up by Mail.) > > Then in a DATA step (of the same program in this case) I have: > > Stratum = INPUT ( Raw_PSU, $Sta85_3. ) ; > > You can have all kinds of INVALUE formats, different length arguments to > function; mixed mode arguments to function, etc.: > > /* Recode Alphabetic "Specialty" Input Field For 1975 and 1980 > Data */ > > INVALUE $Reco1_ UPCASE > 'ADL' = '04' > 'CD ' = '08' > 'CHN' = '12' > 'CHP' = '11' > 'D ' = '09' > 'FP ' = '01' > 'FPS' = '14' > 'GP ' = '01' > 'GS ' = '05' > 'GYN' = '06' > 'HYP' = '11' > 'IM ' = '03' > 'LAR' = '14' > 'N ' = '12' > 'NPM' = '04' > 'OBG' = '06' > : > : > > Or even: > > /* Return Logic Value Indicating Presence of a Valid Code in Slot > Associated With Ordering or Providing Medication Therapy in > 1980 Visits Data. (Also used to get a count of the medi- > cations ordered or provided.) */ > > INVALUE AptCk1_ > '00005' - '33510', > '99980', > '99999' = 1 > Other = 0 ; > > These things are fairly fast to code up, and getting running, although, > I assume there is a lot of SAS overhead involved with this technique. > For really big tables I usually a binary search routine to locate a > (sorted) table entry index of some kind, and extract the function value > I want. > > Best of luck. > > Robert Earl Rose > > TRW SIG Consultant to Technical Services Branch (TSB) > National Center for Health Statistics (NCHS), CDC > Hyattisville, Maryland > ---------- > From: Anthony Ayiomamitis > To: SAS-L@UGA.CC.UGA.EDU > Subject: Re: macro question (easy I hope) > Date: Wednesday, 30 July, 1997 7:24PM > > Mark Smith wrote: > > > > Is there a way in SAS to return a value from a macro. What I want to > > write is something like: > > > > x = %recode(var); > > > > and have the macro return a recoded value to x. > > > > At the moment I am doing it as follows: > > > > %recode(var); x=some_temp_var; > > > > where some_temp_var is a datastep variable created in the macro simply > > for the purpose of passing a value back. Bit kludgy to say the least. > > > > Mark, > > What you are looking to do is basically emulate the functionality of > a customized macro function which is not available/possible to us. > > The best way to have a macro step "return" a value is to have a > macro variable assigned the value you want within the macro step. This > can be done by defining the value directly using a %LET statement within > the macro step or, for example, using the SYMPUT function within a > datastep which in turn is within the macro step (as per your comment > above). > > If you can provide me with a more concrete way of what you are > trying to do, I am sure I can be more definitive in my reply. > > Anthony.


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