Macro Programming (from Fraktal SAS Programming): Unterschied zwischen den Versionen

Aus phenixxenia.org
Zur Navigation springen Zur Suche springen
K
K
 
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
[[Kategorie:zazy]]
 
[[Kategorie:zazy]]
 
{{SeitenNavigation1
 
{{SeitenNavigation1
|hoch=Duck_zazy_com.png
+
|hoch=call a macro bubble 0.png
 
|links=xx_left.png
 
|links=xx_left.png
 
|rechts=xx_right.png
 
|rechts=xx_right.png
Zeile 47: Zeile 47:
 
The code generator properties are best demonstrated when no '''''SAS''''' code is output. To start, we will paraphrase some commands known from the MS-DOS command shell as '''''SAS''''' Macros.
 
The code generator properties are best demonstrated when no '''''SAS''''' code is output. To start, we will paraphrase some commands known from the MS-DOS command shell as '''''SAS''''' Macros.
  
=== DIR ===
+
* [[Macro XSET (from Fraktal SAS Programming)|XSET]]
 
+
* [[Macro XDIR (from Fraktal SAS Programming)|XDIR]]
%MACRO dir(path);
+
* [[Macro XEDIT (from Fraktal SAS Programming)|XEDIT]]
options nonotes nosource;
+
* [[Macro XAMINE (from Fraktal SAS Programming)|XAMINE]]
filename path pipe "dir /b &PATH." lrecl = 256;
 
data _NULL_;
 
infile path;
 
input entries $ 1-256;
 
  put entries;
 
run;
 
options notes;
 
%MEND dir;
 
 
 
=== EDIT ===
 
 
 
%MACRO edt(entry,path);
 
%IF &PATH. eq %THEN %LET path = "C:\users\&SYSUSERID.";
 
filename path "&PATH";
 
DM "PGM";
 
DM "inc path(&ENTRY.)";
 
%MEND edt;
 
 
 
  
 
{{SeitenNavigation1
 
{{SeitenNavigation1
|hoch=Duck_zazy_com.png
+
|hoch=call a macro bubble 0.png
 
|links=xx_left.png
 
|links=xx_left.png
 
|rechts=xx_right.png
 
|rechts=xx_right.png

Aktuelle Version vom 6. Januar 2016, 18:38 Uhr

Zurück

Übersicht

Vorwärts

Positioning

Frankly, a SAS Macro is a code generator.

Even if SAS Macros are feeding their output directly into the SAS compiler, there is no need to restrict the code generated to SAS syntax. Instead, SAS syntax can be used to direct the code generated to any destination in reach, be it local files, portable media or some i-node on the internet. The same flexibility holds for local processes or ports on some IP-Address, but this will be discussed in detail elsewhere in these guidelines.

Programming

The authors did not design a new syntax to program the code generator, but used the same as they did for data processing, which is, the data step language. However, there's one small difference: Where datastep language does distinguish data types such as numeric and character, the macro language does not. All values processed are character, which is, the code composed and finally output, i.e. sent to the SAS compiler.

On the one hand, this is an advantage, since it did not require another learning phase for the novice user, on the other hand this is a solid mess when macro code and data step language are mixed. The latter is possible and widely used by all levels of programmers.

Hello World

The programmer's entry code gives an impression:

%MACRO first;
%PUT Hello World;
%MEND first;

To execute, issue the statement:

%FIRST;

No Open Code

To achieve the same effect as in the example above, this code could also be used:

%PUT Hello World;

Such coding is called OPEN CODE and is possible for rapid prototyping in SAS when there's no logic, looping and branching required. This is not SAS Macro Programming as we want to use the term here.

Throughout these guidelines we will use the full range of Macro Coding to program real SAS Macros, i.e. start each definition with a %MACRO statement and terminate it with a %MEND statement. A referential Example Macro Structure is developed step-by-step and shown in the General Programming Remarks in the introductory chapters.

Annotated SAS Macros

The code generator properties are best demonstrated when no SAS code is output. To start, we will paraphrase some commands known from the MS-DOS command shell as SAS Macros.

Zurück

Übersicht

Vorwärts