110 likes | 329 Views
Tips and Tricks. Program Editor Macros – for PC SAS. Objectives. What are program editor macros? SAS code that is saved and available any time you open SAS When to use macros? Useful for templates Syntax that you rarely use How to create, save and re-use macros?
E N D
Tips and Tricks Program Editor Macros – for PC SAS
Objectives • What are program editor macros? • SAS code that is saved and available any time you open SAS • When to use macros? • Useful for templates • Syntax that you rarely use • How to create, save and re-use macros? • All done in the program editor of the display manager
Examples of PE macros • age=floor(yrdif(brth_dt,<date of interest>,'act/act')); • CASE WHEN SALES BETWEEN 0 AND 10000 THEN ’LOW’ WHEN SALES BETWEEN 10001 AND 15000 THEN ’AVG’ WHEN SALES BETWEEN 15001 AND 20000 THEN ’HIGH’ ELSE ’VERY HIGH’ END AS SALESCAT
Steps for creating a macro • Type in your text into program editor window of display manager • Highlight the text and copy (ctrl-v) • In the display manager menu click ‘Tools’ and then • Click ‘Add Abbreviation’. Fill in the pop-up window and click ‘OK’. The “abbreviation” is the name of the macro • Paste the text that you copied into the window labeled, “Text to insert for abbreviation” • To use the macro: • ‘Tools’ -> ‘Keyboard Macros’ -> ‘Macros’. When you click ‘Macros’, a list of all your macros will appear and you choose the one you want. Or if you remember the name of your macro, type name into program editor window and it will populate. • Text will appear in display manager
Once you store the macro, you can port the macro to any machine or share with others • Trivial example, but real PE macros can save tons of time • Use macros for: exporting to Excel • Importing from Excel • Program templates • Code that I use, but can’t remember the syntax • What will you use the PE macros for …