As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Difference between revisions of "Macro Array Package"

From sasCommunity
Jump to: navigation, search
(polishing intro)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
History note: this is the author's Macro Array, v3, which uses SQL.
 +
 +
* predecessors:
 +
** v1 data null [http://www2.sas.com/proceedings/sugi22/CODERS/PAPER80.PDF %ARRAY: construction and usage of arrays of macro variables]
 +
** v2 sql [http://www2.sas.com/proceedings/sugi29/070-29.pdf Array: Construction and Usage of Arrays of Macro Variables]
 +
* successors:
 +
** v3 [[Macro_Array_v3_sql]] oops! wrong number!
 +
** v4 sql [[Macro_Array-Do]]
 +
** v5.0 [[Macro_AutoMagic]]
 +
** v5.1 [[Macro_CallMacr]]
 +
** v5.2 [[Macro_CallText]]
 +
 
== The Macro Array Package ==
 
== The Macro Array Package ==
(C)  2007 Ronald J. Fehd
+
 
 +
(C)  2007 Ronald J. Fehd
 +
 
 
SAS-L's macro maven
 
SAS-L's macro maven
  
todo: add link to the .pdf and zip file containing the 100 programs in the .pdf
+
Here are links to the .pdf and zip file containing the 100 programs in the .pdf
  
http://www.sascommunity.org/wiki/Image:TheMacroArrayPackage.pdf
+
* [[Image:TheMacroArrayPackage.pdf]]
 
+
* [[Image:TheMacroArrayPackage.zip]]
http://www.sascommunity.org/wiki/Image:TheMacroArrayPackage.zip
+
  
 
Contents
 
Contents
 
+
<pre>
 
1 Introduction                            4
 
1 Introduction                            4
  
 
2 Concepts                                4
 
2 Concepts                                4
 
 
2.1 Development Task Checklists . . . . .  4
 
2.1 Development Task Checklists . . . . .  4
 
 
2.1.1 List Processing . . . . . . . . . .  4
 
2.1.1 List Processing . . . . . . . . . .  4
 
 
2.1.2 Writing Calling Macros  . . . . . .  5
 
2.1.2 Writing Calling Macros  . . . . . .  5
 
 
2.2 Making Unique Lists . . . . . . . . .  5
 
2.2 Making Unique Lists . . . . . . . . .  5
 
 
2.3 Replacing The Dim Function  . . . . .  7
 
2.3 Replacing The Dim Function  . . . . .  7
 
 
2.3.1 Data Step: Array and Dim Function .  7
 
2.3.1 Data Step: Array and Dim Function .  7
 
 
2.3.2 Number of Items . . . . . . . . . .  9
 
2.3.2 Number of Items . . . . . . . . . .  9
 
 
2.3.3 Number of Observations  . . . . . . 10
 
2.3.3 Number of Observations  . . . . . . 10
 
 
2.4 Making Arrays of Macro Variables  . . 11
 
2.4 Making Arrays of Macro Variables  . . 11
 
 
2.4.1 Horizontal List: Scan . . . . . . . 11
 
2.4.1 Horizontal List: Scan . . . . . . . 11
 
 
2.4.2 Vertical List: Call Symputx . . . . 12
 
2.4.2 Vertical List: Call Symputx . . . . 12
 
 
2.4.3 Vertical List: SQL select into  . . 12
 
2.4.3 Vertical List: SQL select into  . . 12
 
 
  
 
3 Demonstration of Usage                  14
 
3 Demonstration of Usage                  14
 
 
3.1 Note: autoexec.sas  . . . . . . . . . 14
 
3.1 Note: autoexec.sas  . . . . . . . . . 14
 
 
3.2 Using Data Sets . . . . . . . . . . . 14
 
3.2 Using Data Sets . . . . . . . . . . . 14
 
 
3.3 Using Lists . . . . . . . . . . . . . 15
 
3.3 Using Lists . . . . . . . . . . . . . 15
 
 
3.4 Using Dictionary Tables: Memnames . . 15
 
3.4 Using Dictionary Tables: Memnames . . 15
 
 
3.5 Note on Using SAShelp Views . . . . . 16
 
3.5 Note on Using SAShelp Views . . . . . 16
 
 
  
 
4 Examples                                17
 
4 Examples                                17
 
 
4.1 Calling Macros  . . . . . . . . . . . 18
 
4.1 Calling Macros  . . . . . . . . . . . 18
 
 
4.1.1 Calling Macros with Data + Var  . . 18
 
4.1.1 Calling Macros with Data + Var  . . 18
 
 
4.1.2 Calling Macros with Lists . . . . . 19
 
4.1.2 Calling Macros with Lists . . . . . 19
 
 
4.1.3 Calling Macros with Either  . . . . 23
 
4.1.3 Calling Macros with Either  . . . . 23
 
 
4.2 Reports . . . . . . . . . . . . . . . 24
 
4.2 Reports . . . . . . . . . . . . . . . 24
 
 
4.2.1 Report Freq . . . . . . . . . . . . 25
 
4.2.1 Report Freq . . . . . . . . . . . . 25
 
 
4.2.2 Report Means  . . . . . . . . . . . 26
 
4.2.2 Report Means  . . . . . . . . . . . 26
 
 
4.2.3 Report sashelp.Shoes Sales  . . . . 26
 
4.2.3 Report sashelp.Shoes Sales  . . . . 26
 
 
  
 
5 Example Applications                    27
 
5 Example Applications                    27
 
 
5.1 Testing . . . . . . . . . . . . . . . 27
 
5.1 Testing . . . . . . . . . . . . . . . 27
 
 
5.1.1 Subroutine: PutParms  . . . . . . . 27
 
5.1.1 Subroutine: PutParms  . . . . . . . 27
 
 
5.1.2 Options Mprint  . . . . . . . . . . 28
 
5.1.2 Options Mprint  . . . . . . . . . . 28
 
 
5.2 Generic Reports . . . . . . . . . . . 28
 
5.2 Generic Reports . . . . . . . . . . . 28
 
 
5.2.1 Report sashelp.Class: Freq  . . . . 28
 
5.2.1 Report sashelp.Class: Freq  . . . . 28
 
 
5.2.2 Report sashelp.Class: Means . . . . 29
 
5.2.2 Report sashelp.Class: Means . . . . 29
 
 
5.2.3 Report sashelp.Shoes: Means . . . . 29
 
5.2.3 Report sashelp.Shoes: Means . . . . 29
 
 
5.3 Specific Report: sashelp.Shoes  . . . 30
 
5.3 Specific Report: sashelp.Shoes  . . . 30
 
 
5.3.1 Report Shoe Sales with Data + Var . 30
 
5.3.1 Report Shoe Sales with Data + Var . 30
 
 
5.3.2 Report Shoe Sales with List . . . . 30
 
5.3.2 Report Shoe Sales with List . . . . 30
  
 
6 The Macros                              32
 
6 The Macros                              32
 
 
6.1 array.sas . . . . . . . . . . . . . . 32
 
6.1 array.sas . . . . . . . . . . . . . . 32
 
 
6.1.1 arrayTestData.sas . . . . . . . . . 36
 
6.1.1 arrayTestData.sas . . . . . . . . . 36
 
 
6.1.2 arrayTestList.sas . . . . . . . . . 37
 
6.1.2 arrayTestList.sas . . . . . . . . . 37
 
 
6.2 vartype.sas . . . . . . . . . . . . . 37
 
6.2 vartype.sas . . . . . . . . . . . . . 37
 
 
6.2.1 vartypeTest.sas . . . . . . . . . . 39
 
6.2.1 vartypeTest.sas . . . . . . . . . . 39
 +
6.2.2 vartypeTest.log . . . . . . . . . . 39
 +
</pre>
 +
 +
== References ==
 +
 +
* Ted Clay
 +
** Tight Looping with Macro Arrays
 +
** http://www2.sas.com/proceedings/sugi31/040-31.pdf
 +
* Ronald Fehd
 +
** %ARRAY: construction and usage of arrays of macro variables
 +
*** http://www2.sas.com/proceedings/sugi22/CODERS/PAPER80.PDF
 +
** ARRAY: Construction and Usage of Arrays of Macro Variables
 +
*** http://www2.sas.com/proceedings/sugi29/070-29.pdf
 +
* [[Journeymens_Tools]]
 +
* [[List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables]]
 +
* [[SASautos_Companion_Reusing_Macros]] modifying options for SAS to find user-written macros
 +
* [[SmryEachVar_A_Data_Review_Suite]] contains a parameterized %include which does similar work as macro array
  
6.2.2 vartypeTest.log . . . . . . . . . . 39
 
  
3/30/2007 11:44AM
+
--macro maven == the radical programmer 3/30/2007 11:44AM
  
[[Category:SAS Code]]
+
[[Category:Macro_Language]]
[[Category:Macro Language]]
+
[[Category:Macros_by_Ron_Fehd]]
 +
[[Category:SAS_Code]]

Latest revision as of 20:34, 11 June 2012

History note: this is the author's Macro Array, v3, which uses SQL.

The Macro Array Package

(C) 2007 Ronald J. Fehd

SAS-L's macro maven

Here are links to the .pdf and zip file containing the 100 programs in the .pdf

Contents

1 Introduction                             4

2 Concepts                                 4
2.1 Development Task Checklists . . . . .  4
2.1.1 List Processing . . . . . . . . . .  4
2.1.2 Writing Calling Macros  . . . . . .  5
2.2 Making Unique Lists . . . . . . . . .  5
2.3 Replacing The Dim Function  . . . . .  7
2.3.1 Data Step: Array and Dim Function .  7
2.3.2 Number of Items . . . . . . . . . .  9
2.3.3 Number of Observations  . . . . . . 10
2.4 Making Arrays of Macro Variables  . . 11
2.4.1 Horizontal List: Scan . . . . . . . 11
2.4.2 Vertical List: Call Symputx . . . . 12
2.4.3 Vertical List: SQL select into  . . 12

3 Demonstration of Usage                  14
3.1 Note: autoexec.sas  . . . . . . . . . 14
3.2 Using Data Sets . . . . . . . . . . . 14
3.3 Using Lists . . . . . . . . . . . . . 15
3.4 Using Dictionary Tables: Memnames . . 15
3.5 Note on Using SAShelp Views . . . . . 16

4 Examples                                17
4.1 Calling Macros  . . . . . . . . . . . 18
4.1.1 Calling Macros with Data + Var  . . 18
4.1.2 Calling Macros with Lists . . . . . 19
4.1.3 Calling Macros with Either  . . . . 23
4.2 Reports . . . . . . . . . . . . . . . 24
4.2.1 Report Freq . . . . . . . . . . . . 25
4.2.2 Report Means  . . . . . . . . . . . 26
4.2.3 Report sashelp.Shoes Sales  . . . . 26

5 Example Applications                    27
5.1 Testing . . . . . . . . . . . . . . . 27
5.1.1 Subroutine: PutParms  . . . . . . . 27
5.1.2 Options Mprint  . . . . . . . . . . 28
5.2 Generic Reports . . . . . . . . . . . 28
5.2.1 Report sashelp.Class: Freq  . . . . 28
5.2.2 Report sashelp.Class: Means . . . . 29
5.2.3 Report sashelp.Shoes: Means . . . . 29
5.3 Specific Report: sashelp.Shoes  . . . 30
5.3.1 Report Shoe Sales with Data + Var . 30
5.3.2 Report Shoe Sales with List . . . . 30

6 The Macros                              32
6.1 array.sas . . . . . . . . . . . . . . 32
6.1.1 arrayTestData.sas . . . . . . . . . 36
6.1.2 arrayTestList.sas . . . . . . . . . 37
6.2 vartype.sas . . . . . . . . . . . . . 37
6.2.1 vartypeTest.sas . . . . . . . . . . 39
6.2.2 vartypeTest.log . . . . . . . . . . 39

References


--macro maven == the radical programmer 3/30/2007 11:44AM