As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
Writing Macro Functions
Q: How do I write a macro that works like a function?
This page contains some guidelines for writing macro functions.
- a macro function is less than a statement, therefore do not generate a SAS semicolon.
- use named parameters
- Q: are you generating SAS statements or macro statements?
%Macro DoThis(var=,value1=,value2) / des = 'description of macro' ; &Var. = sum(&Value1.,&Value2) %*Note: no semicolon on previous line!; %Mend DoThis; *usage:; DATA Work.Sums; %DoThis(var=X,value1=y,value2=z); %DoThis(var=M,value1=N,value2=P);
*name: DoThis.sas; %Macro DoThis2(value1=,value2) / des = 'description of macro' ; sum(&Value1.,&Value2) %*Note: no semicolon on previous line!; %Mend DoThis2; *usage:; DATA Work.Sums2; X = %DoThis2(value1=y,value2=z); if M or %DoThis2(value1=N,value2=P) then output;
- A Cup of Coffee and Proc FCMP: I Cannot Function Without Them
- Create your own Functions using SAS/MACRO and SCL
- Edward Foster
- Macros CallMacro and CallText use SCL functions to read a data set and return values
- Macro Functions: How to Make Them, How to Use Them
- Macro Tips
- Roland Rashleigh-Berry
- Using Macro Functions
- %IFN: A Macro Function
- Chang Y. Chung and Ian Whitlock
-- created by User:Rjf2 15:06, 17 November 2009 (UTC)