BookmarkSubscribeRSS Feed
toconero
Fluorite | Level 6

Hello,

 

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.

 

 

5 REPLIES 5
Kurt_Bremser
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:

https://support.sas.com/training/us/paths/prg.html

 

toconero
Fluorite | Level 6

Thank RW9

RahulG
Barite | Level 11

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.

 

 

Welcome to the Certification Community

 

This is a knowledge-sharing community for SAS Certified Professionals and anyone who wants to learn more about becoming SAS Certified. Ask questions and get answers fast. Share with others who are interested in certification and who are studying for certifications.To get the most from your community experience, use these getting-started resources:

Community Do's and Don'ts
How to add SAS syntax to your post
How to get fast, helpful answers
3 ways to show off your SAS skills

 

Why Get SAS Certified.jpg

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1338 views
  • 9 likes
  • 4 in conversation