Epoch
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 


Rechercher Advanced Search

Keywords

Latest topics
» SAS Macro: Convert numbers (e.g., 1000) to names (e.g., One thousand)
SAS® Macros: Top Ten Questions EmptyMon Jun 10, 2013 2:57 pm by Admin

» SAS Enterprise Guide: Explore Data before you start Analysing
SAS® Macros: Top Ten Questions EmptyMon Jun 10, 2013 2:53 pm by Admin

» Predictive Analytics
SAS® Macros: Top Ten Questions EmptyFri May 31, 2013 3:30 pm by Admin

» Creating Frequency Report and Creating User Defined styles in SAS Add-In for Microsoft Office
SAS® Macros: Top Ten Questions EmptyTue Oct 23, 2012 2:11 pm by pallav

» Prompted Reports in BI Dashboard
SAS® Macros: Top Ten Questions EmptyThu Oct 11, 2012 4:54 pm by kushal

» Free SAS Webinar : Getting Started with SAS Hash Object
SAS® Macros: Top Ten Questions EmptyWed Oct 10, 2012 6:08 pm by pallav

» Which SAS procedure changes the name of a permanent format for a variable stored in a SAS data set?
SAS® Macros: Top Ten Questions EmptyTue Oct 02, 2012 12:47 am by rajin_kumar@yahoo.com

» What is written to SAS Log?
SAS® Macros: Top Ten Questions EmptyTue Oct 02, 2012 12:39 am by rajin_kumar@yahoo.com

» SAS Portal and BI Dashboard: Customizing the Tabs
SAS® Macros: Top Ten Questions EmptyTue Oct 02, 2012 12:33 am by kushal

Affiliates
free forum


SAS® Macros: Top Ten Questions

Go down

SAS® Macros: Top Ten Questions Empty SAS® Macros: Top Ten Questions

Post  pallav Fri May 18, 2012 4:57 pm

1. Can I use SAS functions within the macro facility?
Answer:
Yes, by using the %SYSFUNC macro
function.

Example: %put %sysfunc(date(),worddate20.);

2. What quoting function should I use to mask special characters?

Depends. Use compile-time or execution-time quoting functions for your situation.

Compile-time quoting functions:

 %STR–masks commas, mnemonics, and unmatched quotation marks and parentheses.
 %NRSTR–masks percent signs and ampersands in addition to the other special characters.

 Execution-time quoting functions:


 %BQUOTE–masks special characters and mnemonics in resolved values during macro execution.
 %SUPERQ–masks special characters and mnemonics during macro execution. However, it also prevents further resolution of any macros or macro variables.

Example: Unmatched Quotation Mark (‘)
%let singleq=O'neill;
%put &singleq;

Solution: %STR Function
%let singleq=%str(O%'neill)
%put &singleq;

Example: Percent Sign (%)
%let ex=This macro is called %showme;
%put ex=&ex;

log message

20 %let ex= This macro is called %showme;
WARNING: Apparent invocation of macro SHOWME not resolved.
21 %put ex=&ex;
WARNING: Apparent invocation of macro SHOWME not resolved.

Solution: %NRSTR Function
%let ex=%nrstr(This macro is called %showme);
%put ex=&ex;


3. How do I resolve a macro variable within single quotation marks?

Use the %STR and %UNQUOTE
functions.


4. How do I resolve error messages when output that was generated with the MPRINT system option looks fine?


Use the %UNQUOTE function


5. What are the differences between the autocall facility and the stored compiled macro facility?

Autocall Facility


 Macro source code is implicitly included and compiled to the WORK.SASMACR catalog.
 To use autocall macros, you have to set the MAUTOSOURCE and the SASAUTOS= system options.
 The MAUTOSOURCE option activates the autocall facility.
 The SASAUTOS= option specifies the autocall library or libraries

Stored Compiled Macro Facility

 The stored compiled macro facility provides access to permanent SAS catalogs from which you can invoke compiled macros directly.
 To use these stored compiled macros, you have to set the MSTORED and the SASMSTORE= system options.
 The MSTORED option searches for the compiled macros in a SAS catalog that you reference with the SASMSTORE= option.
 The SASMSTORE= option specifies the libref for the SAS library that contains the stored compiled macros.

6. How do I conditionally execute a macro from within a DATA step?

Use the CALL EXECUTE routine

Example: CALL EXECUTE routine

/* Compile the macro BREAK. The BYVAL */
/* parameter is generated in the CALL */
/* EXECUTE routine. */
%macro break(byval);
data age_&byval;
set sorted(where=(age=&byval));
run;
%mend;
proc sort data=sashelp.class out=sorted;
by age;
run;
options mprint;
data _null_;
set sorted;
by age;
if first.age then call execute(‘%break(‘||age||’)’);
run;


7. Why does my macro variable not resolve?

The macro variable might not resolve for a few reasons:
 macro variable scope: Local macro variables versus global macro variables.
 no step boundary:The DATA step does not have an ending RUN statement before a CALL SYMPUT or a CALL SYMPUTX routine.

Example: No RUN statement before %PUT statement:
data test;
x="MYVALUE";
call symputx('macvar',x);
%put WILL I RESOLVE &macvar?;


 timing issues: a result of using the CALL EXECUTE and CALL SYMPUT routines together.



8. How can I use macros to loop through all files in a directory?

Use the %DO statement


9. Can I use DATA step variables in a %IF-%THEN statement?

No, DATA step variables cannot be used
in %IF-%THEN statements.


10. Why am I getting an error that states that a character operand was found in the %EVAL function?


Use the %SYSEVALF function








pallav

Posts : 98
Join date : 2012-03-14
Location : Ahmedabad

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum