Genericity auf der PhUSE Brighton 2011: Unterschied zwischen den Versionen

Aus phenixxenia.org
Zur Navigation springen Zur Suche springen
Wolf-Dieter Batz (Diskussion | Beiträge)
KKeine Bearbeitungszusammenfassung
Wolf-Dieter Batz (Diskussion | Beiträge)
KKeine Bearbeitungszusammenfassung
Zeile 34: Zeile 34:
;MACRO COMMUNICATION
;MACRO COMMUNICATION
;EXAMPLE CODE
;EXAMPLE CODE
Throughout this paper there will be a number of examples that all make use of the same coding structure and
Throughout this paper there will be a number of examples that all make use of the same coding structure and typographical conventions: (i) All code is embedded in a macro definition block; (ii) all macro processor triggering tokens are upper case; (iii) all other tokens are lower case.
typographical conventions: (i) All code is embedded in a macro definition block; (ii) all macro processor triggering
 
tokens are upper case; (iii) all other tokens are lower case.
%MACRO ts11;
%MACRO ts11;
... Code lines go here ...
... Code lines go here ...
%MEND ts11;
%MEND ts11;
options mprint mlogic;
options mprint mlogic;
%TS11;
%TS11;
options nomprint nomlogic;
options nomprint nomlogic;
 
Since this structure suits quite well for presentation purposes it is not claimed to be state-of-the-art programming or
Since this structure suits quite well for presentation purposes it is not claimed to be state-of-the-art programming or otherwise recommended in a production environment.
otherwise recommended in a production environment.


;TALK TO ME!
;TALK TO ME!
People writing SAS code using the SAS Macro Facility do this for several reasons. One of these definitely emerges
People writing SAS code using the SAS Macro Facility do this for several reasons. One of these definitely emerges from a very personal desire to communicate. On first sight this may appear a bit strange to the naive everyday’s character, but there is strong arguments to do so.
from a very personal desire to communicate. On first sight this may appear a bit strange to the naive everyday’s
 
character, but there is strong arguments to do so.
Assume that you want to output a well known dataset in partitions defined by one criteria and this criteria shall be values used to code the variable ‘sex’. The following approach is likely to not work:
Assume that you want to output a well known dataset in partitions defined by one criteria and this criteria shall be
 
values used to code the variable ‘sex’. The following approach is likely to not work:
%MACRO ts11;
%MACRO ts11;
proc print
proc print
data = sashelp.class
data = sashelp.class
;
;
by sex;
by sex;
run;
run;
%MEND ts11;
%MEND ts11;
options mprint mlogic;
options mprint mlogic;
%TS11;
%TS11;


[[Kategorie:Zazy]][[Kategorie:Twiggi]]
[[Kategorie:Zazy]][[Kategorie:Twiggi]]

Version vom 1. Juni 2025, 14:57 Uhr

New Metadata Concepts Applied to SAS Macro Programming

Genericity

Author
WOLF-DIETER BATZ, Phenix-MTK GmbH 
Summary

Generic Programming is a coding technique that avoids or totally eliminates the use of explicit (hardcoded) information in the source code of a program. Instead, the program is equipped with some "search algorithm" or intelligence to make it find the required information itself from the runtime environment. The presentation will shortly introduce the ideas behind generic programming and then show or demonstrate live an application using these concepts. Special emphasis will be made to an implicit metadata structure referred to as RSDS (Report Specific Data Structure), which is highly efficient in reducing the number of parameters to be passed for a macro call.

Abstract

This paper is not about Macro Programming. It will not attempt to introduce the audience to the universe of the SAS Macro Facility, discussing latest how-to’s dealing with macro triggers, symbol tables, runtime scopes, variable resolution algorithms or the various interfaces to enter or leave this universe. This paper is about Communication. It will raise the question of how to maintain control over of a macro’s behavior when it gets more and more flexible, complex, or powerful in some other sense. The author claims that structural properties of the dataset processed can be utilized to control the macro. A basic approach is presented, of how a macro may extract information from a dataset’s structure and behave accordingly.

MACRO COMMUNICATION
EXAMPLE CODE

Throughout this paper there will be a number of examples that all make use of the same coding structure and typographical conventions: (i) All code is embedded in a macro definition block; (ii) all macro processor triggering tokens are upper case; (iii) all other tokens are lower case.

%MACRO ts11;
... Code lines go here ...
%MEND ts11;
options mprint mlogic;
%TS11;
options nomprint nomlogic;

Since this structure suits quite well for presentation purposes it is not claimed to be state-of-the-art programming or otherwise recommended in a production environment.

TALK TO ME!

People writing SAS code using the SAS Macro Facility do this for several reasons. One of these definitely emerges from a very personal desire to communicate. On first sight this may appear a bit strange to the naive everyday’s character, but there is strong arguments to do so.

Assume that you want to output a well known dataset in partitions defined by one criteria and this criteria shall be values used to code the variable ‘sex’. The following approach is likely to not work:

%MACRO ts11;
proc print
data = sashelp.class
;
by sex;
run;
%MEND ts11;
options mprint mlogic;
%TS11;