Set yourself apart with a SAS Certification credential

The best way to get an advanced programming skills

Reply
Occasional Contributor
Posts: 8

The best way to get an advanced programming skills

[ Edited ]

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.

 

 

Esteemed Advisor
Posts: 6,290

Re: The best way to get an advanced programming skills

This: Macro Basics for New SAS Users should be a fine starting point.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Posts: 6,290

Re: The best way to get an advanced programming skills

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Esteemed Advisor
Posts: 6,989

Re: The best way to get an advanced programming skills

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

 

Occasional Contributor
Posts: 8

Re: The best way to get an advanced programming skills

Thank RW9

Regular Contributor
Posts: 235

Re: The best way to get an advanced programming skills

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.

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 379 views
  • 8 likes
  • 4 in conversation