07-26-2016 06:35 AM - edited 07-26-2016 06:36 AM
I have studied business administration and management, but now I'm working as a statistical, I use SAS in my work. I'm studying for the Base Certification SAS. I'm not good at programming. I find really difficult to understand how a Macro SAS runs.
I would like to get the Advanced Certification SAS, but I found this wall, Macros SAS.
Do you have any suggerations for me to learn Macro SAS ?
Thank you so much.
07-26-2016 06:46 AM
07-26-2016 06:49 AM
The most important thing to keep in mind: the SAS Macro Language is a tool for automated creation of program text; it is not supposed to solve things by itself, but to create code (and code snippets) that then accomplishes the desired task.
07-26-2016 06:51 AM
Its quite a simple concept at its core, imagine it as a kind of Find/Replace system. Its basic function is to remove the need to repeat code or data items across your code. My suggestion is to work backwards to start with, so learn Base SAS - which is the real programming language - fully. Understand data structures and how normalised versus transposed and vice versa can work in different situtations - once you know these you will never *need* to use macro. You may however *want* to use it in certain places, for re-useable code, or repeated code for instance. Also, once you have a firm grasp of Base, write the code which you want to macrotize straight off, for example:
data want1; set sashelp.class; run;
That will run and show we create a dataset want1 based off sashelp.class. Now say we want five datasets - want1 want2 etc. we could copy paste this code, or we could macrotize it.
%macro Loop (times=); %do i=1 %to × data want&i.; set sashelp.class; run; %end; %mend Loop; %Loop (times=5);
What have we done here, well the Base SAS code has not changed much, only the created datastep output name which is now want&i. & is a special character to tell the pre-processor to replace this macro variable with the contents of the macro variable, so on iteration 1, i=1, so &i. becomes 1 = want1. I is defined from the macro do loop - which is virtually the same as the Base SAS datastep loop, except it only functions in macro code. When this macro is called, what the pre-processor is doing is generating the text Base SAS code:
data want1; set sashelp.class; run; data want2; set sashelp.class; run; data want3; set sashelp.class; run; etc. up to 5.
That is basically all macro is, a text generator (or find and replace if you will), and that text which is generated is then fed into the Base SAS compiler - which checks and runs the Base SAS code. So as long as your macro/macro variables resolve into valid executable Base SAS code, you are fine.
If you google, there are plenty of good examples out there, you could also try one of the training's which you would have to pay for:
07-26-2016 06:55 AM
For the perspective of Advance certification, PROC SQL topics covers the most part of it.
In advance sas certification guide, there are only 4 chapters on macros that is what needed to clear the exam. These are well explained in the book.