SAS Macros - Part 1 - Global Macro Variables

SAS Macros are as powerful as a dragon or an eagle, also they haunts SAS coders. Macros are used for automation purpose in a project; when you need to something repetitive, time and again, or your want to design a very complex algorithm in SAS, Macros are there to help you out.

I know these are little difficult to code, but if you imbibe the concept very well in a logical manner, believe me, you will find macros to be your best friend.

Dragons can also be "cute", you just need to control them.  Learn "How to train your dragon?"


Before jumping to concept of Macros, let's first feel an urge to learn these.

Suppose you get weekly sales data files of two countries, one from each Asia and Europe and you are asked to import the files in SAS.
The file of Asian countries are in .txt format and that of Europe are in .csv format.

 First week you get just two files… e.g. Sri Lanka and Germany :

Proc Import datafile = "location\Asia_Sri_Lanka.txt"
out = Asia_Sri_Lanka
dbms = dlm replace;
delimiter = "~";
Run;

Proc Import datafile = "location\Europe_Germany.csv"
out = Europe_Germany
dbms = csv replace;
Run;

What’s the big deal ??? I did It. 

I know you must be feeling like that. Now suppose, you start receiving 20 files from both the continents .... count increases week by week and client starts bombarding you with 1000 files every week. Would you dedicate you entire life just for writing proc Import ?


No ... All you would say "F1" (stands for help in windows OS).

At such moments, the macro would come to rescue you, the way Eagle Gwaihir came for Gandalf the Grey (Movie Lord of the Rings).





Now it is time that I should delve into its concept of AAS macros. Post that only we should start learning Macros.




Enjoy reading our other articles and stay tuned with ...

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.



Family of Macro related articles :





4.  Conditional execution in Macro


5.  Much more

No comments:

Post a Comment

Do provide us your feedback, it would help us serve your better.